My app Login Screen,
On first attempt facebook login button doesn't open safari browser whereas on second attempt it works fine.
Below is my tried code:
FBSDKLoginManager *manager = [FBSDKLoginManager new];
manager.loginBehavior = FBSDKLoginBehaviorBrowser;
NSArray *permissions = @[@"email",@"public_profile"];
[manager logInWithReadPermissions:permissions fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error){
if(error) {
[self showAlertWith:@"Oops!" message:@"Login Failed, try again" handler:nil];
return;
}
if(result.isCancelled) {
[self showAlertWith:@"Oops!" message:@"Login Failed, try again" handler:nil];
return;
}else {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
parameters:@{@"fields": @"picture, name, email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id userinfo, NSError *error) {
if(!error) {
if([FBSDKAccessToken currentAccessToken]) {
[self makeGraphRequest];
}
}else {
EKLog(@"error %@", error);
}
}];
}
}];
Clicking login button for the first time the loginWithReadPermission
is called but callback block is never called, whereas clicking again, the callback handler is called. Any help would be appreciated thanks.
You can try one solution if it work!
declare FBSDKLoginManager *manager
as instance variable or property and initialize it in viewDidload
like,
FBSDKLoginManager *manager = [FBSDKLoginManager new];
And then use!! It might be happened because of local declaration!