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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33148544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:00:25  来源:igfitidea点击:

Facebook share content only shares URL in iOS 9

iosiphonefacebookios9facebook-ios-sdk

提问by Yevhen Dubinin

Share FBSDKShareLinkContentwith FBSDKShareDialogworks fine in iOS 8 but fails to share imageURL, contentTitle, contentDescriptionon iOS 9 devices.

分享FBSDKShareLinkContentFBSDKShareDialogiOS中8工作正常,但无法分享imageURLcontentTitlecontentDescriptioniOS上的9个设备。

The app is built with iOS 9 SDK, Xcode 7, Facebook SDK 4.7.0, all actions mentioned in Preparing Your Apps for iOS9are done. The app is currently not available in App Store and Facebook app is in dev mode.

该应用程序使用 iOS 9 SDK、Xcode 7、Facebook SDK 4.7.0 构建,为 iOS9 准备应用程序中提到的所有操作都已完成。该应用程序目前在 App Store 中不可用,Facebook 应用程序处于开发模式。

The code to present the dialog is pretty common (Swift 2.0):

显示对话框的代码很常见(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()

On iOS 9 Facebook SDK presents native dialog with no image, title and description: On iOS 9 Facebook SDK presents native dialog with no image, title and description

在 iOS 9 Facebook SDK 上显示没有图像、标题和描述的原生对话框: 在 iOS 9 Facebook SDK 上显示没有图像、标题和描述的原生对话框

At the time the dialog is presented, when the FB app is installed on iOS 9 device, there is an error, which when resolved by adding respective URL to Info.plist does not fix the issue. It is just the log statement that does not appear anymore.

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

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

This results in an empty post: empty post shared from iOS 9 device appearance from the web

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

On iOS 8, though, the dialog is presented via FB app OR opens in-app Safari vc when FB app is not installed.

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

For the comparison sake, the same code works from iOS 8 devices:

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

iOS 8 share post appearance

iOS 8 分享帖子外观

UPDATE:

更新:

While @rednuht's answer belowsolves the initial issue, it worth noting about AppStore URL-specific case pointed out by @sophie-fader

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

回答by rednuht

I was having the same issue, and the workaround I'm using is to set the Share Dialog mode to use the native app.

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

I'm using Obj-C, but should be pretty much the same in Swift:

我正在使用 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];

In iOS 9 the user gets the app-switching dialog, but it works fine. There's also FBSDKShareDialogModeWeb, which doesn't have the app-switching dialog, but it doesn't show the image, either.

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

The default is FBSDKShareDialogModeAutomatic, which chooses FBSDKShareDialogModeShareSheet, which is what you're seeing.

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

UPDATE: This is the behavior in iOS9 for the available dialog modes:

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

  • FBSDKShareDialogModeAutomatic: uses ShareSheet, which is the OP case
  • FBSDKShareDialogModeShareSheet: ditto
  • FBSDKShareDialogModeNative: works if the user has the FB app installed, fails silently otherwise. Presents app-switch dialog.
  • FBSDKShareDialogModeBrowser: shares without image
  • FBSDKShareDialogModeWeb: shares without image
  • FBSDKShareDialogModeFeedBrowser: works as intended
  • FBSDKShareDialogModeFeedWeb: works as intended
  • FBSDKShareDialogModeAutomatic:使用ShareSheet,这是OP的情况
  • FBSDKShareDialogModeShareSheet: 同上
  • FBSDKShareDialogModeNative:如果用户安装了 FB 应用程序,则工作,否则静默失败。显示应用程序切换对话框。
  • FBSDKShareDialogModeBrowser: 没有图像的共享
  • FBSDKShareDialogModeWeb: 没有图像的共享
  • FBSDKShareDialogModeFeedBrowser按预期工作
  • FBSDKShareDialogModeFeedWeb按预期工作

"Browser" open Safari full-screen, "Web" opens a webview dialog.

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

I'd go with either of the last two options for iOS9 and Automatic for iOS8.

我会选择 iOS9 的最后两个选项和 iOS8 的 Automatic 中的任何一个。

回答by ViJay Avhad

Solution for the issue is to set the Share Dialog mode to use the native app. In iOS9, swift 2.0

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

For first question: Facebook Share content can share url other than iTunes with content description. If iTunes url is shared it wont share our description.

Next: I was having the same issue, FB Share button clicking redirects me to browser and the workaround I'm using is to set the Share Dialog mode to use the native app.

This occurs consistently if the URL you are sharing is an iTunes App Store URL. Changing the URL to any other website solved the problem. https://developers.facebook.com/docs/sharing/ios"

Note: If your app share links to the iTunes or Google Play stores, we do not post any images or descriptions that you specify in the share. Instead we post some app information we scrape from the app store directly with the Webcrawler. This may not include images. To preview a link share to iTunes or Google Play, enter your URL into the URL Debugger."

第一个问题:Facebook分享内容可以分享除iTunes以外的带有内容描述的url。如果 iTunes url 是共享的,它就不会共享我们的描述。

下一步:我遇到了同样的问题,单击 FB 共享按钮会将我重定向到浏览器,我使用的解决方法是将共享对话框模式设置为使用本机应用程序。

如果您共享的 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()
 }

回答by dzhuowen

to get rid of the error message: -canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629", you can add the following line in the <key>LSApplicationQueriesSchemes</key>array in the info.plist of your project:

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

<string>fbapi20150629</string>

<string>fbapi20150629</string>

回答by Pradeep Mittal

The below code worked like a charm for me in all types of situations :

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

@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()
}

回答by Yogesh Lolusare

Facebook share dialog within your app with title, description & image:

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

  1. iOS:
  1. IOS:

dialog.mode = FBSDKShareDialogMode.ShareSheet //Not tried

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. Implementation from web: The shared link title, description & image should be the response of url, which is brought by Facebook automatically.Ex:
  1. 从网络实现:分享的链接标题、描述和图片应该是url的响应,由Facebook自动带来。前任:

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

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

回答by jsonfellin

If you're sharing a website that you're the webmaster of, the best thing to do is just share the contentURL. Then follow the info here to add Open Graph markup to your HTML file: https://developers.facebook.com/docs/sharing/webmasters

如果您要共享一个您是其网站管理员的网站,最好的办法就是共享contentURL. 然后按照此处的信息将 Open Graph 标记添加到您的 HTML 文件:https: //developers.facebook.com/docs/sharing/webmasters

Facebook will scrape the info from the webpage and populate all the fields from there. To make sure the values looks right, run the debugger:

Facebook 将从网页上抓取信息并从那里填充所有字段。为了确保这些值看起来正确,请运行调试器:

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

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

On that page you can actually force the scrape again, which will be cached.

在该页面上,您实际上可以再次强制抓取,这将被缓存。

回答by tania_S

Facebook title will get shared if we make FBSDKShareLinkContentcontentURL blank.

如果我们将FBSDKShareLinkContentcontentURL 设为空白,Facebook 标题将被共享。

Like for example:

例如:

content.contentURL = [[NSURL alloc] initWithString:@"http://"];

回答by Praveen Sevta

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