FBSDKShareDialog of Facebook SDK is not working on iOS9?

懵懂的女人 提交于 2020-01-09 19:11:30

问题


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?


回答1:


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];



回答2:


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"]];
    }


来源:https://stackoverflow.com/questions/32643522/fbsdksharedialog-of-facebook-sdk-is-not-working-on-ios9

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