gpt4 book ai didi

ios - Facebook iOS SDK 4.1.0 分享回调

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:25:56 24 4
gpt4 key购买 nike

使用这个问题标题中提到的 FBSDK,我在 View Controller 中呈现了一个简单的共享对话框:

// 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];

并实现委托(delegate)方法...

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

到目前为止一切顺利,只要用户在其设备上安装了 Facebook 应用程序。当用户没有安装 Facebook 时会出现此问题。如果是这种情况,Safari 会打开 Facebook 登录流程的网络版本(这很好),但是如果您随后切换回原始应用程序而不登录 Facebook/执行任何其他任务,则上面显示的完成委托(delegate)方法是打电话。

有没有人有解决此问题的经验?似乎应该有一种可靠的方法来确定该帖子是否确实发生过。

注意:上面的代码很伪。在实际实现中,我确实实现了所有委托(delegate)回调(didComplete、didCancel 和 didFail)。

最佳答案

编辑:事实证明,如果设备上安装了 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 将来将 key 从“postId”更改为其他内容怎么办?不太可能,但你明白我的意思)。

关于ios - Facebook iOS SDK 4.1.0 分享回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31169965/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com