SLComposeViewController initWithServiceType无法获得扩展错误

时间:2017-04-29 13:19:54

标签: ios objective-c xcode facebook twitter

我在我的一个应用程序中使用Facebook和Twitter共享。突然在测试时,我开始遇到以下错误。我检查了我的代码,看起来对我来说没问题。

2017-04-29 14:41:19.727248 iCamTranslator[1140:322770] [core] SLComposeViewController initWithServiceType failed to get extension for identifier com.apple.share.Facebook.post
2017-04-29 14:41:19.727642 iCamTranslator[1140:322770] [core] SLComposeViewController dealloc <SLComposeViewController: 0x102992050>
2017-04-29 14:41:19.750499 iCamTranslator[1140:322770] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <AboutViewController: 0x102986900>.'

这是我的代码。请注意,Facebook和Twitter共享都会出错,但我只为Facebook共享编写代码,因为两个错误都相似。

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultCancelled)
        {
            NSLog(@"Cancelled");
        }
        else
        {
            NSLog(@"Done");
        }
        [controller dismissViewControllerAnimated:YES completion:Nil];
    };

    controller.completionHandler =myBlock;
    [controller setInitialText:@"iCamTranslator is a great translation app."];
    [controller addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/icamtranslator/id955853183?mt=8"]];
    [controller addImage:[UIImage imageNamed:@"logo-2.png"]];

    [self presentViewController:controller animated:YES completion:Nil];

    }

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

这个愚蠢的错误是因为我没有在我的设备上更新我的Facebook应用程序。更新后,一切都开始正常。很抱歉打扰你们。