我看到一个奇怪的问题,在我的应用程序中似乎是无效的解析用户会话。我目前使用Facebook登录与解析一起处理我的应用程序中的新用户。
使用解析教程中的boilerplate
代码,两天左右调用[PFUser currentUser]
返回null,用户被要求再次登录。
试图确定它是否与Parse或Facebook相关,我做了以下尝试登录一个有效的Facebook会话时,[PFuser CurrentUser]返回null,它似乎总是工作。
这让我认为这不是Facebook会话,但不知怎的,Parse会话被损坏或返回一些奇怪的东西不时。我确信我没有注销,因为我的注销方法是用户驱动的,而不是在代码的其他地方调用。
下面是我为授权所做的操作:
-(void)authorizeAndSaveUser{
//Check to see if we already have a valid PFUser to avoid authenticating again:
if(![PFUser currentUser]){
//*Patch - occasionally the [PFUser CurrentUser] returns null when we have a logged in user.
//My work around for this is to login with the Facebook Token if we have one
if([FBSDKAccessToken currentAccessToken]){ //<- This always succeeds after the user has been created!
// Log In (create/update currentUser) with FBSDKAccessToken
[PFFacebookUtils logInInBackgroundWithAccessToken:[FBSDKAccessToken currentAccessToken]
block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(@"Uh oh. There was an error logging in with saved FB access token.");
} else {
NSLog(@"Successful login with saved FB access token.");
}
}];
} else { // We have never logged in before so start creating a new user
//Ask for permissions
NSArray *permissionsArray = @[@"public_profile", @"email"];
// Login PFUser using Facebook
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissionsArray block:^(PFUser *user, NSError *error){
if(!error){
if (!user) { //Case where the user cancelled the login
NSLog(@"Uh oh. The user cancelled the Facebook login.");
//The no error case - simply a cancelled login
} else if (user.isNew) { //Net new user
NSLog(@"New User signed up and logged in through Facebook!");
//We have permissions so query Facebook and Write this Data to our App.
[self writeFacebookUserDetailsToParse];
} else { //Returning User
NSLog(@"Existing User logged in through Facebook!");
//We have permissions so query Facebook and Write this Data to our App in order to update profile photos etc.
[self writeFacebookUserDetailsToParse];
}
} else { //The error case
NSLog(@"Uh oh. An error occurred: %@", error);
}
}];
}
}
}
谁能看出什么明显的或提供任何建议?虽然不是一个持续的问题,但每个用户至少每周都会遇到一次弹出的"重新登录",这已经足够让人痛苦了。
提前感谢,
安德鲁似乎我们的朋友在Parse使用框架1.9.0修复了这个问题。查看此处的更改日志:https://www.parse.com/docs/downloads
"修复了从磁盘加载currentUser时不恢复身份验证的问题。"
如果我再次看到这个,我会确认的
安德鲁