2013-09-27 116 views
0

這裏是我做過什麼Facebook上張貼

但是沒有任何反應。我錯過了一步嗎?

這是我使用

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) //check if Facebook Account is linked 
    { 
     mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller 
     mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social plattform to use it, e.g. facebook or twitter 
       [mySLComposerSheet setInitialText:[NSString stringWithFormat:@"Test",mySLComposerSheet.serviceType]]; //the message you want to post 
     [mySLComposerSheet addImage:yourimage]; //an image you could post 
     //for more instance methodes, go here:https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40012205 
     [self presentViewController:mySLComposerSheet animated:YES completion:nil]; 
    } 
    [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) { 
     NSString *output; 
     switch (result) { 
      case SLComposeViewControllerResultCancelled: 
       output = @"Action Cancelled"; 
       break; 
      case SLComposeViewControllerResultDone: 
       output = @"Post Successfull"; 
       break; 
      default: 
       break; 
     } //check if everything worked properly. Give out a message on the state. 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alert show]; 
    }]; 

回答

1

setInitialText方法是不正確的代碼。 如果您使用stringWithFormat發佈serviceType,則需要將其添加到具有「%@」的方法中,否則沒有任何內容可以說它顯示。

總之,只要改變:

[mySLComposerSheet setInitialText:[NSString stringWithFormat:@"Test",mySLComposerSheet.serviceType]]; 

到:

[mySLComposerSheet setInitialText:[NSString stringWithFormat:@"Test %@",mySLComposerSheet.serviceType]];