Facebook iOS SDK 4.1.0共享回调

Ada*_*eld 2 facebook objective-c ios

使用本问题标题中提到的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];
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).

Ada*_*eld 5

编辑:事实证明,如果在设备上安装了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.");
    }
}
Run Code Online (Sandbox Code Playgroud)

虽然这很有效,但似乎并不是一种非常安全的处理方式(如果Facebook将密钥从"postId"更改为未来的其他内容会怎么样?不太可能,但你明白我的观点).