我想在 Facebook 上分享应用程序中的照片和一些文字。我用SLComposeViewController
课堂来分享。
我的问题是,当我点击 Facebook 按钮时,会出现一个对话框,其中包含我要发布的图像,但在模拟器中,默认文本没有出现在设备中,它工作得非常好。此代码在模拟器和设备中都适用于 Twitter。为了更清楚,我添加了代码和图像
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(@"Cancelled");
} else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congratulations!" message:@"Photo is posted to facebook Wall." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
str=[NSString stringWithFormat:@"Text to share"];
[controller setInitialText:str];
[controller addImage:savedImage];
[self presentViewController:controller animated:YES completion:Nil];
}