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 显示没有图像、标题和描述的原生对话框:
出现对话框时,当 FB 应用程序安装在 iOS 9 设备上时,出现错误,通过将相应的 URL 添加到 Info.plist 解决后并没有解决问题。只是不再出现的日志语句。
-canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629"
不过,在 iOS 8 上,对话框是通过 FB 应用程序显示的,或者在未安装 FB 应用程序时打开应用程序内 Safari vc。
为了比较起见,相同的代码适用于 iOS 8 设备:
更新:
同时 @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/