Reputation: 4733
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:
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:
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:
UPDATE:
While @rednuht's answer below solves the initial issue, it worth noting about AppStore URL-specific case pointed out by @sophie-fader
Upvotes: 38
Views: 44823
Reputation: 1613
For Swift >= 5.0, You can follow the tutorial below...
Facebook, Messenger - Photo, Video, Link sharing in iOS Swift.
Upvotes: 0
Reputation: 593
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()
}
Upvotes: 2
Reputation: 149
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];
Upvotes: 0
Reputation: 1370
Facebook title will get shared if we make FBSDKShareLinkContent
contentURL blank.
Like for example:
content.contentURL = [[NSURL alloc] initWithString:@"http://"];
Upvotes: 0
Reputation: 31
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.
Upvotes: 2
Reputation: 2212
Facebook share dialog within your app with title, description & image:
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)
meta http-equiv="content-type" content="text/html; charset=utf-8"> title>MY SHRED URL TITLE meta content='" + imageUrl + "' property='og:image'/>
Upvotes: 2
Reputation: 2700
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()
}
Upvotes: 10
Reputation: 1812
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 caseFBSDKShareDialogModeShareSheet
: dittoFBSDKShareDialogModeNative
: works if the user has the FB app installed, fails silently otherwise. Presents app-switch dialog.FBSDKShareDialogModeBrowser
: shares without imageFBSDKShareDialogModeWeb
: shares without imageFBSDKShareDialogModeFeedBrowser
: works as intendedFBSDKShareDialogModeFeedWeb
: 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.
Upvotes: 59
Reputation: 172
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>
Upvotes: 7