Facebook and twitter login with Parse iOS only works once

匿名 (未验证) 提交于 2019-12-03 02:35:01

问题:

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!

回答1:

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.



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!