我正在为iOS实现Parse/Facebook登录,它运行得很好——我用自己的FB用户登录,一切都很好。
但现在我想从另一个FB用户(测试人员的帐户)登录我的iOS应用程序。这就是我所做的:
-
在我的iPhone上转到我的FB应用程序,注销,然后用我的测试帐户再次登录。
-
回到我的iOS/Parse应用程序,尝试使用Facebook登录。结果是我用自己的帐户登录了!
我卸载了该应用程序,并从xCode重新运行它,登录了Facebook,然后我又使用了自己的帐户。
无论我做什么,我都会回到自己的账户。看起来Parse或FB正在以某种方式缓存我的信息。如何取消缓存以重新开始?
这是我的登录方法:
- (void)loginWithFB {
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
// Login PFUser using facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
[_activityIndicator stopAnimating]; // Hide loading indicator
if (!user) {
if (!error) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error" message:@"Uh oh. The user cancelled the Facebook login." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil];
[alert show];
} else {
NSLog(@"Uh oh. An error occurred: %@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error" message:[error description] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil];
[alert show];
}
} else if (user.isNew) {
NSLog(@"User with facebook signed up and logged in!");
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = appDelegate.tabBarController;
[appDelegate.tabBarController setSelectedIndex:3];
[self.navigationController pushViewController:[[MyTrack alloc] init] animated:YES];
} else {
NSLog(@"User with facebook logged in!");
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *facebookUsername = [result objectForKey:@"username"];
[PFUser currentUser].username = facebookUsername;
[[PFUser currentUser] saveEventually];
NSLog(@"Welcome Screen I am %@", [[PFUser currentUser] username]);
} else {
NSLog(@"Error getting the FB username %@", [error description]);
}
}];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = appDelegate.tabBarController;
[appDelegate.tabBarController setSelectedIndex:0];
}
}];
[_activityIndicator startAnimating]; // Show loading indicator until login is finished
}
请在退出时尝试此操作
[FBSession.activeSession close];
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession = nil;