Ada*_*eld 2 facebook objective-c ios
使用本问题标题中提到的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];
Run Code Online (Sandbox Code Playgroud)
并实现委托方法......
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(@"Sweet, they shared.");
}
Run Code Online (Sandbox Code Playgroud)
只要用户在他们的设备上安装了Facebook应用程序,到目前为止一切都很好.当用户没有安装Facebook时会出现问题.如果是这种情况,Safari会打开Facebook登录流程的Web版本(这很好),但是如果您在没有登录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.");
}
}
Run Code Online (Sandbox Code Playgroud)
虽然这很有效,但似乎并不是一种非常安全的处理方式(如果Facebook将密钥从"postId"更改为未来的其他内容会怎么样?不太可能,但你明白我的观点).
| 归档时间: |
|
| 查看次数: |
920 次 |
| 最近记录: |