Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 Facebook SDK Login/Share

I have run into an issue using the latest Facebook SDK (4.6) on iOS 9. To authorize a user, I use the FBSDKLoginManager. I have tried setting this:

loginManager.loginBehavior = FBSDKLoginBehaviorNative;

But the SDK still seems to always use an SFSafariViewController to authorize Facebook.

Here is the problem I am facing. If a user has the FB app installed on their device with FacebookAccountA, then tries to authenticate with my app, they are presented this SFSafariViewController and they can authenticate the app with FacebookAccountB (a separate FB account).

Then in the app, I try to share with the following:

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:shareString];

FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.shareContent = content;
dialog.delegate = self;
[dialog show];

The default setting for the share dialog ends up being the FBSDKShareDialogModeShareSheet. The share sheet presents in the app correctly, and the post seems to work, however the link is posted to FacebookAccountA (the native app account), NOT FacebookAccountB (the one that authenticated with my app).

So, if a user happens to authenticate my app with a different facebook account than they are signed into on their native app, they can end up posting to an account that was different than the one they used to authenticate my app. Is there a way to prevent this?

Thanks in advance.

like image 838
haplo1384 Avatar asked Sep 23 '15 17:09

haplo1384


2 Answers

This is by design.

In FB SDK v4.6 and v3.24, we default to Safari View Controller rather than fast-app-switching to the native Facebook app. In iOS 9 the fast-app-switch flow generates two interstitials "ExampleApp would like to open Facebook" and "Facebook would like to open ExampleApp".

For the hundreds of millions of people who are signed into Safari on iOS, they have an awesome experience.

like image 92
Simon Cross Avatar answered Oct 14 '22 06:10

Simon Cross


Use SLComposerViewController for Fb sharing. It will use your ios device default Facebook sdks login or your installed application login.

Below is the reference for this: Tutorial for SLComposeViewController sharing

Hope this helps!

like image 1
Dharmesh Siddhpura Avatar answered Oct 14 '22 06:10

Dharmesh Siddhpura