ios - Facebook 分享内容在 iOS 9 中只分享 URL

标签 ios iphone facebook ios9 facebook-ios-sdk

Share FBSDKShareLinkContent with FBSDKShareDialog 在 iOS 8 中工作正常但无法共享 imageURL, contentTitle, contentDescription 在 iOS 9 设备上。

该应用程序是使用 iOS 9 SDK、Xcode 7、Facebook SDK 4.7.0 构建的,所有操作均在 Preparing Your Apps for iOS9 中提及完成。该应用目前在 App Store 中不可用,Facebook 应用处于开发模式。

显示对话框的代码很常见(Swift 2.0):

let content = FBSDKShareLinkContent()

content.contentURL = <URL to the app in the App Store>
content.imageURL = <valid image URL>
content.contentTitle = <some title>
content.contentDescription = <some descr>

let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = viewController
shareDialog.shareContent = content
shareDialog.delegate = self

if !shareDialog.canShow() {
    print("cannot show native share dialog")
}

shareDialog.show()

在 iOS 9 上,Facebook SDK 显示没有图像、标题和描述的原生对话框: On iOS 9 Facebook SDK presents native dialog with no image, title and description

出现对话框时,当 FB 应用程序安装在 iOS 9 设备上时,出现错误,通过将相应的 URL 添加到 Info.plist 解决后并没有解决问题。只是不再出现的日志语句。

-canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629"

这会导致一个空帖子: empty post shared from iOS 9 device appearance from the web

不过,在 iOS 8 上,对话框是通过 FB 应用程序显示的,或者在未安装 FB 应用程序时打开应用程序内 Safari vc。

为了比较起见,相同的代码适用于 iOS 8 设备:

iOS 8 share post appearance

更新:

同时 @rednuht's answer below解决了最初的问题,值得注意的是AppStore URL-specific case pointed out by @sophie-fader

最佳答案

我遇到了同样的问题,我使用的解决方法是将共享对话框模式设置为使用 native 应用程序。

我正在使用 Obj-C,但在 Swift 中应该几乎相同:

FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = viewController;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeNative; // if you don't set this before canShow call, canShow would always return YES
if (![dialog canShow]) {
    // fallback presentation when there is no FB app
    dialog.mode = FBSDKShareDialogModeFeedBrowser;
}
[dialog show];

在 iOS 9 中,用户会看到应用程序切换对话框,但它工作正常。还有 FBSDKShareDialogModeWeb,它没有应用程序切换对话框,但也不显示图像。

默认为 FBSDKShareDialogModeAutomatic,它选择 FBSDKShareDialogModeShareSheet,这就是您所看到的。

更新:这是 iOS9 中可用对话模式的行为:

  • FBSDKShareDialogModeAutomatic:使用 ShareSheet,这是 OP 的情况
  • FBSDKShareDialogModeShareSheet:同上
  • FBSDKShareDialogModeNative:如果用户安装了 FB 应用程序,则工作正常,否则静默失败。显示应用程序切换对话框。
  • FBSDKShareDialogModeBrowser: 无图分享
  • FBSDKShareDialogModeWeb: 无图分享
  • FBSDKShareDialogModeFeedBrowser:按预期工作
  • FBSDKShareDialogModeFeedWeb:按预期工作

“浏览器”打开 Safari 全屏,“Web”打开一个 webview 对话框。

我会选择 iOS9 的最后两个选项和 iOS8 的自动。

关于ios - Facebook 分享内容在 iOS 9 中只分享 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33148544/

相关文章:

iphone - iOS:在单独的线程中反序列化 JSON?

ios - 有没有办法使用 Appcelerator Titanium 修改 iOS webView 中的上下文菜单?

iphone - 如何处理多个委托(delegate)

facebook - 如何通过 GRAPH API 获取 Facebook 照片隐私设置

jquery - 使用 jquery 动态添加 facebook 之类的按钮

ios - 两个不同的tableview xCode之间的冲突

ios - 无法更改搜索栏背景颜色

iphone - iPhone 的 Objective-C 中的面向方面编程

ios - 我的 iOS 应用程序被踢出挂起状态的速度太快了。我不知道是什么在后台占用 CPU

javascript - 如何将对 JS 函数的引用作为参数传递给 ExternalInterface 调用?