[英]Facebook iOS SDK v 4.1.0 in Swift with Cocoapods: cannot import modules
[英]Facebook iOS SDK 4.1.0 Share Callback
使用此问题标题中提到的FBSDK,我在视图控制器中显示了一个简单的共享对话框:
// 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登录流程的网络版本(这很好),但是如果您随后又切换回原始应用程序而不登录Facebook /执行任何其他任务,则上面显示的完成委托方法为调用。
有没有人有解决此问题的经验? 似乎应该有一种可靠的方法来确定该职位是否确实存在。
注意:上面的代码是相当伪的。 在实际的实现中,我确实实现了所有的委托回调(didComplete,didCancel和didFail)。
当然,发布后,我偶然发现了答案。 如果实际发生共享,则在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”更改为其他名称,这是怎么回事?不太可能,但我明白了)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.