Facebook共享内容仅在iOS 9中共享URL

Yev*_*nin 38 iphone facebook ios facebook-ios-sdk ios9

分享FBSDKShareLinkContentFBSDKShareDialog在iOS 8的精品工程,但无法分享imageURL,contentTitle,contentDescriptioniOS上的9个设备.

该应用程序使用iOS 9 SDK,Xcode 7,Facebook SDK 4.7.0 构建,完成了为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()
Run Code Online (Sandbox Code Playgroud)

在iOS 9上,Facebook SDK提供了没有图像,标题和描述的原生对话框: 在iOS 9上,Facebook SDK提供了没有图像,标题和描述的原生对话框

在显示对话框时,当在iOS 9设备上安装FB应用程序时,会出现错误,通过向Info.plist添加相应的URL解决此问题无法解决问题.它只是不再出现的日志语句.

-canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629"
Run Code Online (Sandbox Code Playgroud)

这导致一个空帖子: 来自网络的iOS 9设备外观共享的空帖子

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

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

iOS 8分享帖子外观

更新:

虽然@ rednuht的答案解决了最初的问题,但值得注意的是@ sophie-fader指出的AppStore特定URL的案例

red*_*uht 58

我遇到了同样的问题,我正在使用的解决方法是将Share Dialog模式设置为使用本机应用程序.

我正在使用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];
Run Code Online (Sandbox Code Playgroud)

在iOS 9中,用户获得应用程序切换对话框,但它工作正常.还有FBSDKShareDialogModeWeb,它没有应用程序切换对话框,但它也没有显示图像.

FBSDKShareDialogModeAutomatic选择的默认值是,FBSDKShareDialogModeShareSheet您正在看到的内容.

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

  • FBSDKShareDialogModeAutomatic:使用ShareSheet,这是OP案例
  • FBSDKShareDialogModeShareSheet:同上
  • FBSDKShareDialogModeNative:如果用户安装了FB应用程序,则无效,否则无效.显示app-switch对话框.
  • FBSDKShareDialogModeBrowser:没有形象的股票
  • FBSDKShareDialogModeWeb:没有形象的股票
  • FBSDKShareDialogModeFeedBrowser:按预期工作
  • FBSDKShareDialogModeFeedWeb:按预期工作

"浏览器"打开Safari全屏,"Web"打开一个webview对话框.

我会选择iOS9的最后两个选项和iOS8的Automatic.


ViJ*_*had 10

该问题的解决方案是将共享对话框模式设置为使用本机应用程序.在iOS9中,swift 2.0

对于第一个问题:Facebook共享内容可以与iTunes共享内容描述以外的网址.如果共享iTunes网址,则不会分享我们的说明.

下一篇:我遇到了同样的问题,FB Share按钮点击将我重定向到浏览器,我正在使用的解决方法是将Share Dialog模式设置为使用本机应用程序.

如果您要共享的URL是iTunes App Store URL,则会一致地发生这种情况.将URL更改为任何其他网站解决了该问题.https://developers.facebook.com/docs/sharing/ios "

注意:如果您的应用共享指向iTunes或Google Play商店的链接,我们不会发布您在共享中指定的任何图像或说明.相反,我们会直接使用Webcrawler发布我们从应用商店中获取的一些应用信息.这可能不包括图像.要预览iTunes或Google Play的链接共享,请在URL调试器中输入您的URL."

  func shareFB(sender: AnyObject){

    let content : FBSDKShareLinkContent = FBSDKShareLinkContent()

    content.contentURL = NSURL(string: "//URL other then iTunes/AppStore")
    content.contentTitle = “MyApp”
    content.contentDescription = “//Desc“

    content.imageURL = NSURL(string:“//Image URL”)


    let dialog : FBSDKShareDialog = FBSDKShareDialog()
    dialog.mode = FBSDKShareDialogMode.Native
  // 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()
 }
Run Code Online (Sandbox Code Playgroud)


小智 7

摆脱错误消息: -canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629",您可以<key>LSApplicationQueriesSchemes</key>在项目的info.plist 中的数组中添加以下行:

<string>fbapi20150629</string>