Facebook对话框中不显示默认字符串

时间:2015-04-28 06:15:03

标签: ios objective-c iphone facebook ios8.3

我想在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];
}

enter image description here

2 个答案:

答案 0 :(得分:0)

str=@"Text to share";

[controller setInitialText:str];


          OR
[controller setInitialText:@"Text to share"];

像这样更改您的代码并尝试...

答案 1 :(得分:0)

- (IBAction)facebookPost:(id)sender {

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [mySLComposerSheet setInitialText:@"Social Framework test!"];

        [mySLComposerSheet addImage:[UIImage imageNamed:@"myImage.png"]];

        [mySLComposerSheet addURL:[NSURL URLWithString:@"http://stackoverflow.com"]];

        [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

             switch (result) {
                 case SLComposeViewControllerResultCancelled:
                     NSLog(@"Post Canceled");
                     break;
                 case SLComposeViewControllerResultDone:
                     NSLog(@"Post Sucessful");
                     break;

                 default:
                     break;
             }
         }];

        [self presentViewController:mySLComposerSheet animated:YES completion:nil];
    }
}

试试这个........这就是我为我的项目所做的事情