Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login doesn't work/stuck with Latest Facebook SDK

I am running with an issue with using Facebook SDK(4.9.1) which opens in app browser for login if no system account present.

Login from system Facebook account works well. I am using the following code

FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
   manager.loginBehavior = FBSDKLoginBehaviorSystemAccount;
   [manager logInWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] fromViewController:controller handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
            if (error) {
                success(kFacebookStatusFailed);
            } else if (result.isCancelled) {
                success(kFacebookStatusCancelled);
            } else {
                success(kFacebookStatusSuccess);
            }
}];

I have correctly done all required info.plist settings defined here.

The problem is when it logs in using inapp browser, actually using SafariViewController found by debugging. It goes through all login process but in the end it stucks in a white blank screen and doesn't dismiss, see screenshot below

enter image description here

Have tried all possible steps but not able to get over it. But when I setup fresh project having nothing just the above login code and proper settings, all worked fine.

The only difference in the Fresh Project and Original Project is number of different frameworks used in the app, like Crashlytics, Fabric, Instabug, Google Frameworks etc. Is there any reason that I should suspect these framework that is causing problem, I think NO. So, what could be the problem, anyone who faced the same problem and can help me will be greatly appreciated.

Thank You.

like image 821
iphonic Avatar asked Feb 04 '16 05:02

iphonic


2 Answers

I was having the same problem. Add this to your AppDelegate:

In AppDelegate.m

  1. In application:didFinishLaunchingWithOptions:

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];
    }
    
  2. Add the following method to your AppDelegate.m:

    -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
      return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    }
    

I don't know if the SafariViewController checks for the application:openURL:sourceApplication:annotation but this worked for me. Give it a try. I hope it works for you.

Source: https://developers.facebook.com/docs/ios/getting-started

like image 165
Axort Avatar answered Nov 12 '22 02:11

Axort


Yes There is a problem with Login

-(IBAction)fbAction:(id)sender

{

    FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
     manager.loginBehavior=FBSDKLoginBehaviorWeb;
    
    if ([FBSDKAccessToken currentAccessToken])
    {
        [manager logOut];
        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
        
        [self fetchUserInfo];
    }
    else
    {
        [manager logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
         {
             if (error)
             {
                 NSLog(@"Login process error");
             }
             else if (result.isCancelled)
             {
                 NSLog(@"User cancelled login");
             }
             else
             {
                 NSLog(@"Login Success");
                 if ([result.grantedPermissions containsObject:@"email"])
                 {
                     NSLog(@"result is:%@",result);
                     [self fetchUserInfo];
                     
                 }
             }
         }];
    }

}

-(void)fetchUserInfo

{

        if ([FBSDKAccessToken currentAccessToken])
        {
            NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
            
            [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email"}]
             //[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, first_name, last_name, picture.type(large), email"}]
             
             startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                 if (!error)
                 {
                     NSLog(@"results:%@",result);
                     
                     NSString *email = [result objectForKey:@"email"];
                     NSString *userId = [result objectForKey:@"id"];
                     
                     if (email.length >0 )
                     {
                         
                         NSLog(@"email %@,userid %@",email,userId);
                     }
                     else
                     {
                         NSLog(@"Facebook email is not verified");
                     }
                 }
                 else
                 {
                     NSLog(@"Error %@",error);
                 }
             }];
        }
    
}
like image 29
Uma Madhavi Avatar answered Nov 12 '22 03:11

Uma Madhavi