iOS Facebook SDK MessageDialog错误202

我想在我的iOS应用程序中与FBSDK建立Facebook共享.

我一直在阅读文档here,目前有

[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

使用内容对象 – FBSDKShareLinkContent.

但是,在尝试使用Facebook Messenger共享指定的类似方法时,

[FBSDKMessageDialog showWithContent:content delegate:self];

我正在崩溃.我发现错误并将其记录在其中一个委托方法中,并指出“操作无法完成.(com.facebook.sdk.share error 202.)

搜索了这个特定的错误,但没有找到任何直接相同的错误.这是完整的代码

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:kAPPShareLink];
content.contentDescription = kAPPShareDescription;
content.contentTitle = kAPPShareTitle;

if (buttonIndex == 0) {
    // Facebook

    [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
} else if (buttonIndex == 1) {
    // Facebook Messenger

    [FBSDKMessageDialog showWithContent:content delegate:self];
}

请原谅我,如果我遗漏了一些明显的东西,但是当this documentation读取时,我认为FBSDKMessageDialog showWithContent:方法的工作方式与FBSDKShareDialog showFromViewController相同:这对我有用.

>我正在使用最新版本的XCode和iOS8.

解决方法

我必须登录然后发布,这是它的工作原理:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];


[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result,NSError *error)
{

    if (error)
    {
    // Process error
    }
    else if (result.isCancelled)
    {
        // Handle cancellations
    }
    else
    {
        FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
        content.contentURL = [NSURL URLWithString:@"https://developers.facebook.com/"];

        FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
        messageDialog.delegate = self;
        [messageDialog setShareContent:content];

        if ([messageDialog canShow])
        {
            [messageDialog show];
        }
        else
        {
            // Messenger isn't installed. Redirect the person to the App Store.
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/en/app/facebook-messenger/id454638411?mt=8"]];
        }

    }
}];

和股份代表:

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
    NSLog(@"didCompleteWithResults");
}

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError ::: %@",error);
}

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
    NSLog(@"sharerDidCancel");
}

编辑:

[messageDialog canShow]在iPad上返回NO,在iPhone上运行正常

Facebook Developers forum上发布了这个问题.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...