8

With Xcode7, I upgrade Facebook SDK to pod FBSDKShareKit (4.6.0). And I have added Facebook scheme to WhiteList as below. reference: https://developers.facebook.com/docs/ios/ios9

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
</array>

However, the following code only show iOS default social dialog on iOS9. The same code with the same binary on iOS8 can open Facebook app and show the Sharing Dialog properly.

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.example.com"]];
content.contentDescription = @"Test";
[FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];

I guess Facebook app is not found on iOS9 and then show the default social dialog. Even no error message showed.

Do I miss anything? Or, it's an iOS9 bug?

derjohng
  • 877
  • 2
  • 9
  • 18
  • I got the same problem. I think I followed everything on the doc. If Facebook app is not found it should still use the web form of sharing. And it works fine in simulator. – mrhangz Sep 18 '15 at 05:11

2 Answers2

32

I'm guessing Facebook changed the behaviour because iOS 9 now pops up a dialog asking if you would like to "Open Facebook?" when doing app-switching. Even for FBSDKLoginManager, the app-switching (native) method seems to be less preferred than a modal UIWebView.

However, you can still force the share dialog to switch to the Facebook app (assuming you have your application plist setup as described in https://developers.facebook.com/docs/ios/ios9) by using this method:

FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbauth2://"]]){
    dialog.mode = FBSDKShareDialogModeNative;
}
else {
    dialog.mode = FBSDKShareDialogModeBrowser; //or FBSDKShareDialogModeAutomatic
}
dialog.shareContent = content;
dialog.delegate = self;
dialog.fromViewController = self;
[dialog show];
wilsontgh
  • 9,602
  • 1
  • 16
  • 12
  • 1
    Thanks a lot. This works, and this is what I want.^^ – derjohng Sep 18 '15 at 06:47
  • 2
    In addition, this won't work if the fb app is not installed so you'd better check it and if it's not installed, use FBSDKShareDialogModeFeedBrowser instead. – mrhangz Sep 18 '15 at 08:24
  • @mrhangz I have edited the solution to include a check if the Facebook App is installed. I was assuming it would automatically fallback to other modes, but it doesn't. Thanks! Also, I prefer the FBSDKShareDialogModeBrowser over FBSDKShareDialogModeFeedBrowser. – wilsontgh Sep 19 '15 at 10:28
  • To me it seems like a facebook sdk bug. I couldn't use anything except FBSDKShareDialogModeFeedBrowser (not even automatic), if it works for you it's great :) – mrhangz Sep 29 '15 at 08:49
  • Be careful with this solution, because from 4.1 there are significant changes about exception list for iOS9. – Resty Jan 22 '16 at 13:15
  • yeah none of these fallback modes work on iOS9 if the Facebook app isn't installed – Cbas Mar 17 '16 at 00:12
  • 1
    Just tested on iOS 11. `dialog.mode = FBSDKShareDialogModeBrowser` is what I needed to do if the Facebook app isn't installed, otherwise it wouldn't show anything. – Alex Wally Nov 02 '17 at 09:08
  • Is it possible to share photo to facebook using FBSDKShareKit without having native facebook app? I tried with below code `let share_dialog = FBSDKShareDialog() share_dialog.mode = .browser share_dialog.delegate = self share_dialog.fromViewController = self share_dialog.shareContent = content share_dialog.show()` Its not working. – Neelam Pursnani Aug 03 '18 at 09:29
1

In iOS 9 below is the only solution that worked for me to detect if facebook app is installed in the device or not:

 NSString *urlString = @"fbapi://";
    NSURL *url1 = [NSURL URLWithString:urlString];

    if ([[UIApplication sharedApplication] canOpenURL:url1]) {
        [[UIApplication sharedApplication] openURL:url1];
    }
    else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itunes link for download app"]];
    }
TharakaNirmana
  • 10,237
  • 8
  • 50
  • 69