Blank page while logging in with Facebook SDK on iOS 10
Asked Answered
S

6

5

In my app I'm using facebook SDK to login a user like this:

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

Everything was working good on iOS 9, but on iOS 10 when the safari view controller is presented (managed by facebook SDK) I get a blank page right away and nothing happens: Blank Page

Found a lot of issues regarding this blank page on facebook login, but always related to delegation after login, in this case I'm getting the blank page right after pressing the "login with facebook" button.

Anyone passed by the same issue?

Stellular answered 16/9, 2016 at 12:58 Comment(0)
U
8

use FBSDKLoginBehaviorWeb:

FBSDKLoginManager *loginMgr = [[FBSDKLoginManager alloc] init];
loginMgr.loginBehavior = FBSDKLoginBehaviorWeb;
[loginMgr logInWithReadPermissions
Unlucky answered 17/9, 2016 at 7:59 Comment(1)
Wow !! The FBSDKLoginBehaviorWeb works, shows dialog for FB login but FBSDKLoginBehaviorBrowser one is not working.Sludgy
C
3

I got exactly the same issue on my App. Finally I figured it out that the reason is because I was presenting an UIAlertView (as an activity indicator) right before calling this FB login method with the second parameter "fromViewController" set to nil.

- (void)logInWithReadPermissions:(NSArray *)permissions
          fromViewController:(UIViewController *)fromViewController
                     handler:(FBSDKLoginManagerRequestTokenHandler)handler

According to my test, it's fine to set the fromViewController to nil as long as you are NOT presenting any alert view at the time since the FB SDK is able to get the parent view controller correctly by itself. However if you want to present any alert view (though it seems not a logical UI design) you would have to set the fromViewController explicitly so the FB login process works as expected. This is not an issue prior to iOS 10 but apparently something changed internally.

Cosset answered 16/9, 2016 at 17:11 Comment(2)
Thank you for your reply, I don't have any UIAlertView being presented, but you think it is something UI-related that is preventing the browser to load properly, am I correct?Stellular
I think the point is that you should pass in the correct view controller to the FB login method, no matter whether you are presenting any other views. If you still see the same issue after you make sure you pass in the correct parent view controller, then there might be something else you need to fix.Cosset
F
2

Solution for Swift 3 and iOS 10. Use the Facebook Login alert view

    let manager = FBSDKLoginManager()
    manager.loginBehavior = FBSDKLoginBehavior.web
    manager.logIn(withReadPermissions: ["public_profile", "email", "user_friends"], from: self, handler: { (pResult, pError) -> Void in
        ....
    })
Flaminius answered 3/3, 2017 at 13:30 Comment(0)
T
0

This Work for me May Help You

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions: @[@"public_profile", @"email"] fromViewController:UIApplication.sharedApplication().keyWindow?.rootViewController handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
...
}

instead of self use UIApplication.sharedApplication().keyWindow?.rootViewController

Tashinatashkent answered 30/9, 2016 at 5:8 Comment(0)
C
0

If you have updated the SDK in recent times then just add the following method in appdelegate:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options 
{
return [[FBSDKApplicationDelegate sharedInstance] application:app
                                                      openURL:url
                                            sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                   annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

And as mentioned in another answer you can use the alternative method which will always open the Facebook login in a Webview as popover.

FBSDKLoginManager *loginMgr = [[FBSDKLoginManager alloc] init];
loginMgr.loginBehavior = FBSDKLoginBehaviorWeb;
Clichy answered 20/1, 2017 at 11:4 Comment(0)
F
-1

I also get this error when using FBSDKLoginKit and FBSDKShareKit to login and share link in my application: Get blank page while log in, share and like with Facebook SDK on iOS 10 with Facebook SDK 4.15.1

Filamentous answered 17/9, 2016 at 2:19 Comment(4)
Ask as a question, not as an answer to another question.Caston
Sorry, but I think it 's the same problem, and the answer will be the same so I try to make clear for everybody about this problem.Roast
I get it. So, post a new question, and reference this question in a link.Caston
Thank you, I already do this #39545252Roast

© 2022 - 2024 — McMap. All rights reserved.