【问题标题】:FBSDKSharing Callback not returning resultsFBSDKSharing 回调不返回结果
【发布时间】:2015-09-28 15:05:24
【问题描述】:

在我的 iOS 应用中,我有一个 Facebook 分享按钮,它会打开一个 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。

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

- (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 上的帖子,回调也会被触发,但没有结果。

如何区分以便仅在用户实际发布到 Facebook 时才显示已发布提醒?

【问题讨论】:

    标签: ios facebook facebook-graph-api


    【解决方案1】:

    根据documentationresult 可能为 nil 或为空。无法保证您实际上会得到一些可被您的应用用来确认已分享/发布的内容。

    【讨论】:

      【解决方案2】:

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

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

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

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

      【讨论】:

        【解决方案3】:

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

        - (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 帖子以获取更多详细信息。

        【讨论】:

          猜你喜欢
          • 2016-02-05
          • 1970-01-01
          • 1970-01-01
          • 2018-09-20
          • 2016-07-22
          • 2023-03-16
          • 1970-01-01
          • 2011-07-11
          • 1970-01-01
          相关资源
          最近更新 更多