Facebook share content only shares URL in iOS 9

半世苍凉 提交于 2019-11-28 03:28:08
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:

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.

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

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

  • 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

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

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

Solution for the issue is to set the Share Dialog mode to use the native app. In 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."

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

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:

<string>fbapi20150629</string>

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

  1. iOS:

dialog.mode = FBSDKShareDialogMode.ShareSheet //Not tried

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:

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

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

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:

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

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

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

Facebook title will get shared if we make FBSDKShareLinkContent contentURL blank.

Like for example:

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!