iosfacebookfacebook-loginios10fbsdkloginkit

FBSDKLoginManager logInWithReadPermissions: fromViewController: handler: completion not called on app first run


I have a Facebook login-enabled app and for some reason FBSDKLoginManager logInWithReadPermissions: fromViewController: handler: is not called on the very first run of my app after installation. If I just kill my app (even without trying to login to Facebook or do anything: trying to login on first open or not doesn't change anything) and open it again, it works perfectly.

Why?

(I've checked the view controller passed to the method is not nil and is the current view controller)

Here is my login code:

+(void)loginWithFacebookWithCompletion:(ULCompletion)completion{
    [[[FBSDKLoginManager alloc] init] logInWithReadPermissions:FACEBOOK_READ_PERMISSIONS fromViewController:[ULMasterViewController instance] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if(result.token){
          ...
        }
[...]

The rest is irrelevant as the completion block is not called at all (not even with an error). I've got the FACEBOOK_READ_PERMISSIONS hardcoded:

#define FACEBOOK_READ_PERMISSIONS (@[@"user_friends", @"user_birthday", @"email", @"user_photos"])

And finally, [ULMasterViewController instance] is valid (not nil, and has its view in hierarchy (otherwise it complains about view not being in hiearchy, also tried that)).


Solution

  • This working in my case .

    1 .Create instance of FBloginManager in interface.

    FBSDKLoginManager *manager
    

    2 .Initialise in ViewDidLoad.

    manager = [FBSDKLoginManager new]
    

    3 .And finally call login permission method using this instace of FBLoginManager.