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的更多细节。