Facebook iOS SDK 4.1.0共享callback

使用这个问题标题中提到的F​​BSDK,我在视图控制器中提供一个简单的共享对话框:

// Setup the content for the share FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init]; content.contentURL = linkUrl; content.contentDescription = description; content.contentTitle = title; content.imageURL = imageUrl; // Show the share dialog [FBSDKShareDialog showFromViewController:controller withContent:content delegate:someDelegate]; 

并实施委托方法…

 - (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results { NSLog(@"Sweet, they shared."); } 

到目前为止,只要用户在自己的设备上安装了Facebook应用程序,这一切都不错。 用户没有安装Facebook时出现问题。 如果是这种情况,Safari会打开Facebook的loginstream程的网页版本(这是正常的),但是如果您在没有login到Facebook /执行任何其他任务的情况下切换回原始应用程序,则上面显示的完成委托方法是调用。

有没有人有任何这方面的解决方法的经验? 似乎应该有一个可靠的方法来确定职位是否确实发生。

注意:上面的代码是非常伪的。 在实际的实现中,我确实实现了所有的委托callback(didComplete,didCancel和didFail)。

编辑:事实certificate,如果Facebook应用程序安装在设备上,则调用完成方法时结果字典为空。 为了克服这个问题,需要做一个检查来查看Facebook是否被首先安装。

当然,发布后,我偶然发现了答案。 如果实际发生共享,则在didCompleteWithResults方法中返回的结果字典将包含一个postId键。 所以逻辑如下:

 - (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results { NSURL *fbURL = [NSURL URLWithString:@"fb://"]; if (![[UIApplication sharedApplication] canOpenURL:fbURL]) if (results[@"postId"]) { NSLog(@"Sweet, they shared, and Facebook isn't installed."); } else { NSLog(@"The post didn't complete, they probably switched back to the app"); } } else { NSLog(@"Sweet, they shared, and Facebook is installed."); } } 

虽然这是有效的,但似乎并不是一个很安全的方式去做事情(如果Facebook将密钥从“postId”更改为未来的其他内容,不太可能,但是你明白了我的观点)。