FBSDKSharingcallback不返回结果
在我的iOS应用程序中,我有一个Facebook共享button,打开一个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中打开一个窗口,要求他们login到Facebook。
如果用户没有login就返回到我的应用程序,FBSDKSharing didCompleteWithResultscallback被调用,但是没有结果返回:
- (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]; }); }
但是,如果用户login并完成Facebook上的post,则callback也会被触发而没有结果。
我如何区分,因此如果用户实际上已经发布到Facebook,我只显示“发布提醒”。
根据文件 , result
可能是零或空。 不能保证你会得到一些可以被你的应用程序用来确认分享/发布的东西。
看起来FB改变了一些委托,当用户共享委托方法将运行与空结果,所以如果你检查这个方法中的东西,以确保张贴正确的只是删除它
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
当用户取消共享时,此方法将运行
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
解决scheme是检查委托方法sharer:didCompleteWithResults:
如果用户已将Facebook安装为@Adam Eisfeldbuild议:
- (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
键(一个string数组),并添加fb
检查这个post的更多细节。
- 从应用程序链接到Safari“添加到主屏幕”?
- Facebook iOS SDK 3.1:“错误:HTTP状态码:400”
- 对于使用Facebook iOS SDK的混合SSO场景,为我们自定义用户logging生成密码/密钥的最佳方式是什么?
- embedded式Facebook的post在UIWebView中显示不正确
- 如何运行React-Native示例?
- 我怎样才能得到用户信息使用Facebook的SDK 4.1在iOS?
- presentShareDialogWithParams发布到FB墙,但callback处理程序结果说错误
- 如果用户通过Facebooklogin,如何以编程方式启动到另一个viewController
- Facebook连接后对话框文本?