FBSDK共享回调不返回结果 [英] FBSDKSharing Callback not returning results

查看:495
本文介绍了FBSDK共享回调不返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS应用中,我有一个Facebook分享按钮,打开一个FBSDKShareDialog:

In my iOS app, I have a Facebook share button, which opens up a FBSDKShareDialog:

-(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应用程序,在Safari中打开一个窗口,要求他们登录Facebook。

If the user doesn't have the Facebook app, it opens up a window in Safari that asks them to log into Facebook.

如果用户在没有登录的情况下返回到我的应用程序,则FBSDKSharing didCompleteWithResults回调被调用,但没有结果返回:

If the user returns to my app without having logged in, the FBSDKSharing didCompleteWithResults callback gets called, but no results are returned:

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
        NSLog(@"results: %@", results);
        NSLog(@"posted to facebook successfully!");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:@"Posted!"
                                                   delegate:self
                                          cancelButtonTitle:nil
                                          otherButtonTitles:nil];
        [alert show];
        double delayInSeconds = 1.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)  (delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [alert dismissWithClickedButtonIndex:0 animated:YES];
    });
}

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

However, if the user logs in and completes the post on Facebook, the callback also gets triggered with no results.

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

How do I differentiate so I only show the Posted alert if the user has actually posted to Facebook?

推荐答案

根据文档 result 可能为零或为空。不能保证您实际获得可以由您的应用使用的东西,以确认已发布的分享/信息。

According to the documentation, result may be nil or empty. There is no guarantee that you will actually get something back that could be used by your app to confirm a share/post has been made.

这篇关于FBSDK共享回调不返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆