FBSDKSharing回调没有返回结果

时间:2015-09-28 15:05:25

标签: ios facebook facebook-graph-api

在我的iOS应用程序中,我有一个Facebook共享按钮,它打开了一个FBSDKShareDialog:

IF (type == 'a') {
    proper "required" and validation rules the additional fields
} ELSEIF (type == 'b') {
    proper "required" and validation rules the additional fields
} ELSEIF (type == 'c') {
    proper "required" and validation rules the additional fields
}

如果用户没有Facebook应用程序,它会在Safari中打开一个窗口,要求他们登录Facebook。

如果用户在未登录的情况下返回我的应用程序,则会调用FBSDKSharing didCompleteWithResults回调,但不会返回任何结果:

-(IBAction)post:(id)sender{

    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentURL = [NSURL URLWithString:self.setShareURL];
    NSLog(@"facebook share url: %@", self.setShareURL);
    content.contentTitle= [NSString stringWithFormat: @"%@'s set", self.username];
    content.contentDescription=@"#spinturntable";

    FBSDKShareDialog *fbdialog = [[FBSDKShareDialog alloc] init];

    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbauth2://"]]){
        fbdialog.mode = FBSDKShareDialogModeNative;
    }
    else {
        fbdialog.mode = FBSDKShareDialogModeBrowser; //or FBSDKShareDialogModeAutomatic
    }
    fbdialog.shareContent = content;
    fbdialog.delegate = self;
    fbdialog.fromViewController = self;
    [fbdialog show];

}

但是,如果用户登录并在Facebook上完成帖子,则回调也会被触发而没有结果。

我如何区分所以如果用户实际发布到Facebook,我只显示已发布的提醒?

3 个答案:

答案 0 :(得分:1)

根据documentationresult可能为零或空。我们无法保证您实际上会收到一些可供您的应用用来确认共享/帖子的内容。

答案 1 :(得分:0)

看起来FB在Delegate上改变了一些东西 当用户共享委托方法时,它将以空结果运行,因此,如果您在此方法中检查某些内容以确保正确发布的帖子只是删除它

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results

当用户取消分享时,此方法将运行

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer

答案 2 :(得分:0)

解决方案是检查委托方法sharer:didCompleteWithResults:,如果用户安装了Facebook @Adam Eisfeld建议:

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results{

    // check if user has facebook app installed
    NSURL *fbURL = [NSURL URLWithString:@"fb://"];
    // there is no facebook app installed
    if (![[UIApplication sharedApplication] canOpenURL:fbURL]){
        // facebook is not intalled check the keys
        if (results.allKeys.count !=0){
            // success you can get your post ID
        }else {
            // if resutlst.allKeys == 0 means user press Done button 
        }
    } else {
        // the share is successfully and facebook is installed
    }
}

从iOS9.0开始,不要忘记添加.plist文件LSApplicationQueriesSchemes键(字符串数组)并添加fb检查this帖子以获取更多详细信息。