38

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

Community
  • 1
  • 1
Yevhen Dubinin
  • 4,657
  • 3
  • 34
  • 57
  • 1
    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 Dec 10 '15 at 17:50

9 Answers9

59

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.

Yevhen Dubinin
  • 4,657
  • 3
  • 34
  • 57
rednuht
  • 1,724
  • 16
  • 27
  • I just ran some tests with other modes: - FBSDKShareDialogModeBrowser - no image - FBSDKShareDialogModeFeedWeb - works! Now, since there's no error if the app is not installed, it would probably be better to use FeedWeb for all cases. – rednuht Oct 15 '15 at 15:37
  • FBSDKShareDialogModeFeedBrowser also works. I'm adding all those to the answer for completion sake. – rednuht Oct 15 '15 at 15:43
  • When the FB app is not installed the presentation fails silently with `error==nil` returned to the delegate callback `func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!)`. – Yevhen Dubinin Oct 15 '15 at 15:48
  • The `.Native` & `.FeedBrowser` combination indeed works for both iOS 9 & iOS 8 with or without FB app installed. I have updated the code for this answer. Thank you, guys! – Yevhen Dubinin Oct 15 '15 at 15:58
  • Is it possible for sharing individually?Using FBSDKMessageDialog? – user3575114 Oct 27 '15 at 08:41
  • @user3575114 user could choose an audience to share a post with via `FBSDKShareDialog`. Specifically, to share with other user only, one could choose "Specific friends..." option from **To:** menu. – Yevhen Dubinin Nov 10 '15 at 01:51
  • 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 Dec 10 '15 at 17:52
  • 1
    @Rushabh can you confirm that title and description are not nilor empty and the URL is not an AppStore URL? – Yevhen Dubinin Jan 06 '16 at 12:45
  • Looks that with the latest facebook sdk the content is not shown. – Mejdi Lassidi Jun 02 '16 at 07:13
  • this is ignoring anything I put in the "quote" section if I choose one of the Feed options. Choosing ShareSheet includes the quote, but ignores the custom title, description, and image. Frustrating! – JAB Jun 28 '16 at 01:38
  • guys, i have added the same +++ dialog.mode = FBSDKShareDialogMode.Native +++ it worked fine for one day, but when i shared very next day its not working what's the issue with this i am not getting. Any help is appreciated. Thanks – veeresh kumbar May 26 '17 at 05:12
10

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()
 }
ViJay Avhad
  • 2,684
  • 22
  • 26
  • i have added the same +++ dialog.mode = FBSDKShareDialogMode.Native +++ it worked fine for one day, but when i shared very next day its not working what's the issue with this i am not getting. Any help is appreciated. Thanks. – veeresh kumbar May 26 '17 at 05:11
  • For sure, its not only the day change, u must check for code, any other things such device you have tested on, have tried on device with FB app ? or simulator. Please check all other factors. – ViJay Avhad May 26 '17 at 06:12
  • Yes i tested on the device with FB app installed but same issue. :( – veeresh kumbar May 26 '17 at 06:15
7

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>

dzhuowen
  • 172
  • 4
  • 1
    This is stated in the [doc](https://developers.facebook.com/docs/ios/ios9) in FAQ section at the bottom, which I followed and mentioned that. Adding this to `LSApplicationQueriesSchemes` does not solve the issue itself. – Yevhen Dubinin Nov 27 '15 at 17:07
2

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

Yogesh Lolusare
  • 2,162
  • 1
  • 24
  • 35
2

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.

jsonfellin
  • 31
  • 2
2

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()
}
Pradeep Mittal
  • 595
  • 1
  • 8
  • 19
  • Thank you for this. Facebook with its native views is so pain in the a... This method is must've if your phone is not connected to Facebook and u want to present login dialog then share. – Pan Mluvčí Oct 12 '17 at 10:29
0

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

Like for example:

content.contentURL = [[NSURL alloc] initWithString:@"http://"];
marius
  • 7,766
  • 18
  • 30
tania_S
  • 1,350
  • 14
  • 23
0
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];
Praveen Sevta
  • 149
  • 1
  • 3
0

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

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

emraz
  • 1,563
  • 20
  • 28