Facebook login via Safari or FB app not working
This method works great when the user is logged into Facebook in iOS8 settings.
But if it doesn't, it tries to log in using Safari or the Facebook iOS app, and once the user is redirected back to the app, it just shows this registered message instead of logging in to the user.
And I am using Parse.com SDK.
Post registered
NSLog(@"Uh oh. The user cancelled the Facebook login.");
Facebook login method
-(void)loginButtonPressed
{
[PFFacebookUtils initializeFacebook];
NSArray *permissionsArray = @[@"user_about_me"];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
NSString *errorMessage = nil;
if (!error) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
errorMessage = @"Uh oh. The user cancelled the Facebook login.";
} else {
NSLog(@"Uh oh. An error occurred: %@", error);
errorMessage = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error"
message:errorMessage
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"Dismiss", nil];
[alert show];
} else {
if (user.isNew) {
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"User with facebook signed up and logged in!");
} else {
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"User with facebook logged in!");
}
// [self _presentUserDetailsViewControllerAnimated:YES];
}];
}
+3
source to share
1 answer
Adding this line to AppDelegate.m
fixes the problem.
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
0
source to share