Facebook Login - iOS 9 - Without Safari

19,120

Solution 1

Seems there's no way to get the previous behavior using newests FB SDKs in iOS9+. You can use an old SDK to do that. Here's a response from the facebook to that question: enter image description here

Solution 2

From now You can change loginBehavior to FBSDKLoginBehaviorSystemAccount, so FBSDKLoginManager gets Facebook logged in user from iOS Facebook Settings ;)

FBSDKLoginManager *fbLogin = [[FBSDKLoginManager alloc] init];
fbLogin.loginBehavior = FBSDKLoginBehaviorSystemAccount;

From FBSDKLoginManager:

Declaration: FBSDKLoginBehaviorSystemAccount
Description: If the account is not available to the app (either not configured by user or as determined by the SDK) this behavior falls back to FBSDKLoginBehaviorNative.
Note: If the account is not available to the app (either not configured by user or as determined by the SDK) this behavior falls back to FBSDKLoginBehaviorNative.

Solution 3

If you want to use the latest SDK and also the native login behaviour on iOS 9

Edit FBSDKServerConfiguration.m's function to always return true

- (BOOL)useNativeDialogForDialogName:(NSString *)dialogName
{
  return @YES;
}

Falling back to Safari still work if the Facebook app isn't installed

Solution 4

I noticed that in both changelogs, as well:

Facebook SDK for iOS Changelog v4.x

(v4.6.0 - September 10, 2015) In addition, the SDK dialogs such as Login, Like, Share Dialogs automatically determine the best UI based on the device, including SFSafariViewController instead of Safari. Follow the our Preparing for iOS 9 guide.

Facebook SDK for iOS Changelog v3.x

(v3.24.0 - September 10th 2015) In addition, the SDK dialogs such as Login, Like, Share Dialogs automatically determine the best UI based on the device, including SFSafariViewController instead of Safari. Follow the our Preparing for iOS 9 guide.

Solution 5

I followed the doc here: https://developers.facebook.com/docs/ios/ios9

after adding point 2 and 3, my app switches to native facebook app for login...

Share:
19,120
Admin
Author by

Admin

Updated on July 15, 2022

Comments

  • Admin
    Admin almost 2 years

    It worked fine to login with logInWithReadPermissions in iOS 8, but as soon after the update to iOS 9 it keeps opening Safari or a modal UIWebView.

    Does anyone have the same issue?

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login setLoginBehavior:FBSDKLoginBehaviorNative];
    [login logInWithReadPermissions:@[@"public_profile",@"email"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        NSLog(@"");
    }];