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

FBSDKShareDialog共享FBSDKShareLinkContent适用于iOS 8,但无法在iOS 9设备上共享imageURLcontentTitlecontentDescription

该应用程序使用iOS 9 SDK,Xcode 7,Facebook SDK 4.7.0构build,所有在准备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提供没有图像,标题和说明的本机对话框: 在iOS 9上,Facebook SDK提供没有图像,标题和说明的本机对话框

当出现对话框时,当FB应用程序安装在iOS 9设备上时,会出现错误,通过向Info.plist添加相应的URL解决此错误时不能解决问题。 这只是不再出现的日志声明。

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

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

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

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

iOS 8分享文章外观

更新:

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

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

我使用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 ,它selectFBSDKShareDialogModeShareSheet ,这就是你所看到的。

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

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

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

我会selectiOS9的最后两个选项,iOS8的自动选项。

解决此问题的方法是将“共享对话框”模式设置为使用本机应用程序。 在iOS9中,swift 2.0

对于第一个问题:Facebook共享内容可以共享除iTunes以外的其他地址,并带有内容描述 如果iTunesurl是共享的,它不会分享我们的描述。

下一步:我遇到了同样的问题,FB Sharebutton点击redirect到浏览器,我使用的解决方法是将Share Dialog模式设置为使用本地应用程序。

如果您要共享的url是iTunes App Storeurl,则会始终如此。 更改URL到任何其他网站解决了这个问题。 https://developers.facebook.com/docs/sharing/ios

注意:如果您的应用共享了iTunes或Google Play商店的链接,我们不会发布您在共享中指定的任何图片或说明。 相反,我们用Webcrawler直接从app store中发布一些应用信息。 这可能不包括图像。 要预览链接共享到iTunes或Google Play,请在URLdebugging器中input您的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() } 

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

<string>fbapi20150629</string>

如果您分享的网站是您的网站pipe理员,那么最好的办法就是分享内容url。 然后按照这里的信息添加开放graphics标记到您的HTML文件: https : //developers.facebook.com/docs/sharing/webmasters

Facebook将从网页上刮取信息,并从那里填充所有的字段。 为了确保值看起来正确,运行debugging器:

https://developers.facebook.com/tools/debug/

在那个页面上,你可以再次强制擦除,这将被caching。

下面的代码在所有types的情况下对我来说都是一种魅力:

 @IBAction func facebookTap() { let content = FBSDKShareLinkContent() content.contentTitle = imageTitle content.contentURL = URL(string: "http://technokriti.com/") content.imageURL = URL(string: self.imageURL) content.contentDescription = imageDescription let dialog : FBSDKShareDialog = FBSDKShareDialog() dialog.fromViewController = self dialog.shareContent = content dialog.mode = FBSDKShareDialogMode.feedWeb dialog.show() } 

在您的应用程序中的Facebook共享对话框标题,描述和图像:

  1. iOS版:

dialog.mode = FBSDKShareDialogMode.ShareSheet //未尝试

 or //Working for me: let linkcontent: FBSDKShareLinkContent = FBSDKShareLinkContent() linkcontent.contentURL = videoURL // linkcontent.contentDescription = videoDesc // linkcontent.contentTitle = videoTitle // linkcontent.imageURL = imageURL FBSDKShareDialog.showFromViewController(self, withContent: linkcontent, delegate: self) 
  1. 从网站实现:共享链接标题,描述和图片应该是由Facebook自动带来的url的回应。 例如:

meta html =“content-type”content =“text / html; charset = utf-8”> title> MY SHRED URL TITLE meta content ='“+ imageUrl +”'property ='og:image'/>

如果我们使FBSDKShareLinkContent contentURL为空,Facebook标题将被共享。

例如:

 content.contentURL = [[NSURL alloc] initWithString:@"http://"]; 
 This works for me:- FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init]; content.contentURL = [NSURL URLWithString:APP_STORE_LINK]; content.imageURL=[NSURL URLWithString:IMAGE_LINK]; FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init]; dialog.shareContent = content; dialog.fromViewController = self; dialog.mode = FBSDKShareDialogModeFeedBrowser; [dialog show];