9

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.

haplo1384
  • 1,206
  • 1
  • 12
  • 29
  • If you want to login through facebook app look at my answer here http://stackoverflow.com/a/32821579/3002083 – Iraklii Sep 28 '15 at 11:15
  • 1
    Thanks, it seems the only option is what you said. I don't mind login through the SFSafariViewController, if it didn't cause the problem I'm seeing. – haplo1384 Oct 01 '15 at 13:32
  • @haplo1384 did you got any solution for above issue? – Abilash Balasubramanian May 13 '17 at 09:18
  • @AbilashBNair i have moved on from this project and have not tested recently. in the answer posted below Simon Cross indicated that it was an issue that was being worked on by Facebook, so my hope would be that they have resolved it by now. – haplo1384 May 13 '17 at 16:38

3 Answers3

5

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.

Simon Cross
  • 13,315
  • 3
  • 32
  • 26
  • 2
    Thanks Simon, I have no problem with the Safari View Controller being used to authenticate the user. The issue is that even after authenticating with the Safari View Controller, the FBSDKShareDialog seems to default to using the Facebook account of the native app, which may be different than the Facebook account the person had used to authenticate my app with via the Safari View Controller. Is that by design? – haplo1384 Oct 01 '15 at 19:52
  • @haplo1384 its "by design" in that its a known issue. We're looking at ways to detect, and mitigate this case. – Simon Cross Oct 02 '15 at 05:30
  • 3
    @Simon Cross As far as I know you have close to one billion people using the Facebook APP. Isn't the userbase bigger which just has to push two buttons rather than the ones who have to enter their username and password? – Petrescu Silviu Oct 06 '15 at 14:23
  • @PetrescuSilviu - the interstitials add friction which make the fast-app-switch flow less effective. The Safari View Controller approach gets better over time as more and more people are signed into Safari. We're continuing to monitor this very closely. – Simon Cross Oct 06 '15 at 15:15
  • 9
    @Simon Cross, having to type in username and password in Safari seems to add more friction than the two interstitials. Do you have a sense of the rate of drop-offs between the two approaches? – cpungaliya Oct 15 '15 at 15:30
  • 1
    I'm ok with using the Sarari View Controller - I'm just concerned that many users do not know their fb passwords. Usually people sign in to the fb app and never sign out. They will have to go out of their way to reset passwords and do all this extra work just so that they can use your app. – TheRealRonDez Oct 29 '15 at 22:33
  • It'd be nice if we still at least had the option to request that the Facebook sdk use the native app if available. The UX of the safari view controller feels like it could be a phishing attack presenting a Facebook "like" ui to snag credentials whereas with fast app switching there's no doubt you are actually signing in via Facebook. I assume Facebook has done the research to back this up but I wish the decision weren't so heavy handed. – ToddH Nov 18 '15 at 00:15
  • @SimonCross ok, so this unifies the user experience, which is a good thing, however why doesn't the share dialog use the same session as the login manager? Why do users need to login again, after they previously logged successfully? – Cristik Oct 19 '17 at 05:43
1

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!

Community
  • 1
  • 1
Dharmesh Siddhpura
  • 1,610
  • 12
  • 22
  • Thanks for the answer, but I want to share using the Facebook credentials that were used to authenticate my app (via SFSafariViewController). This will not do that, will it? – haplo1384 Sep 23 '15 at 17:28
  • Same issue for me too. Any solution? – Femina Dec 11 '15 at 09:07
0

Yes, it is by design on iOS 9, but we can easily work around it!

let dialog = FBSDKShareDialog()
dialog.mode = .Native
if !dialog.canShow() {
    self.mode = .Automatic
}

Yay!

Valentin Shergin
  • 7,166
  • 2
  • 50
  • 53