38
votes

Share FBSDKShareLinkContent with FBSDKShareDialog works fine in iOS 8 but fails to share imageURL, contentTitle, contentDescription on iOS 9 devices.

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

The code to present the dialog is pretty common (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

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.

-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

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

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

iOS 8 share post appearance

UPDATE:

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

9
I can't able to share Title and Description on Facebook using iOS 9 device i am using same code which is given in answer how can i share title and description ?Rushabh

9 Answers

59
votes

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.

10
votes

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

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>

2
votes

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'/>

2
votes

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.

2
votes

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

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

Like for example:

content.contentURL = [[NSURL alloc] initWithString:@"http://"];
0
votes
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];
0
votes

For Swift >= 5.0, You can follow the tutorial below...

Facebook, Messenger - Photo, Video, Link sharing in iOS Swift.