1

I'm using the twitter and Facebook login in the Parse SDK. For every app launch I can log into each service once, but when I logout using [PFUser logOut] I am unable to log in again. The [PFFacebookUtils logInWithPermissions] block never gets called either with a user or an error.

My (Facebook) Login Code is:

- (IBAction)facebookLogin:(id)sender {
    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) {
                NSLog(@"User with facebook signed up and logged in!");
            } else {
                NSLog(@"User with facebook logged in!");
            }
        }
    }];
}

My logout code is:

- (IBAction)loginButton:(id)sender {
    if([PFUser currentUser]) {
        [PFUser logOut];        
        NSLog(@"User is %@", [PFUser currentUser]);
        NSLog(@"Facebook session is %@", [PFFacebookUtils session]);
        NSLog(@"Facebook session is %@", FBSession.activeSession.observationInfo);
    } else {
        [self performSegueWithIdentifier:@"loginScreenSegue" sender:self];
    }
}

Everything logs (null).

I assumed that as the behaviour was the same with Twitter, that it might be related to the OAuth related methods in my AppDelegate:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                        withSession:[PFFacebookUtils session]];
}

- (BOOL) application:(UIApplication *)application
       handleOpenURL:(NSURL *)url
   sourceApplication:(NSString *)sourceApplication
          annotation:(id)annotation {
    return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                        withSession:[PFFacebookUtils session]];
}

But have done a lot of research and don't seem to be missing anything...

I also have these in the AppDelegate:

- (void)applicationWillResignActive:(UIApplication *)application {
    [[PFFacebookUtils session] close];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    [[PFFacebookUtils session] close];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}

Any help would be very gratefully received!

  • Are you using anonymous users? – soulshined Dec 30 '14 at 09:49
  • First of all you call log out the user in your LOGIN methods which is the opposite of what you are trying to achieve. Also you close the session every time the app resigns active state - this happens on screen lock and home button. Are you sure you want that logic? – i-konov Dec 30 '14 at 10:44
  • @soulshined - thank you, I'm not using anonymous users and have them turned off. – Steve Knight Dec 30 '14 at 14:05
  • @Ivan - My login button is a toggle - so when logged in the button changes to 'logout' and when the user is logged out it will perform a modal segue to the login view controller - thank you for the close session comments, I added it in to applicationWillResignActive when tired and out of desperation! – Steve Knight Dec 30 '14 at 14:05

2 Answers2

0

In you logout method, you should clear the Facebook session token as well like below:

[[FBSession activeSession]closeAndClearTokenInformation];

This will clear the active Facebook session's token.

Henit Nathwani
  • 442
  • 3
  • 10
  • thank you - I have added that, but it makes no difference. I just tried using ParseUI instead of my own login view controller with exactly the same issue which makes me think it is something external or in the appDelegate. – Steve Knight Dec 30 '14 at 14:09
0

OK, I finally solved this. The problem was that in my app setup on twitter, the permissions were set to 'Read only', not 'Read and Write'.

Changing this setting solved the problem with both facebook and twitter.