[英]PFUser currentUser returns nil
I'm using Parse SDK, login and signup are working perfectly : [PFUser currentUser]
is returning the current user. 我正在使用Parse SDK,登录和注册工作正常:
[PFUser currentUser]
返回当前用户。
But after restarting app, [PFUser currentUser]
is returning nil. 但是重新启动应用程序后,
[PFUser currentUser]
返回nil。
Why is the application not persisting the session ? 为什么应用程序不保留会话?
Login code (from parse.com) I'm using : 登录代码(来自parse.com)我正在使用:
[PFUser logInWithUsernameInBackground:self.username.text password:self.password.text
block:^(PFUser *user, NSError *error) {
if (user) {
// Do stuff after successful login.
} else {
// The login failed. Check error to see why.
}
}];
EDIT 2: Create new project, it works. 编辑2:创建新项目,它可以工作。 I don't know how and why, but it works.
我不知道如何以及为什么,但是可以。
EDIT: There is no logout
in the whole project 编辑:整个项目中没有
logout
It looks like you are calling .logout
somewhere, in which case the app will return nil
for [PFUser currentUser]
. 似乎您在某处调用
.logout
,在这种情况下,该应用将为[PFUser currentUser]
返回nil
。
The current user will persist from session to session if you do not automatically log out the user. 如果您没有自动注销该用户,则当前用户将在会话之间保持不变。
PFUser *currentUser = [PFUser currentUser];
if (currentUser) {
//save the installation
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation[@"installationUser"] = [[PFUser currentUser]objectId];
// here we add a column to the installation table and store the current user’s ID
// this way we can target specific users later
// while we’re at it, this is a good place to reset our app’s badge count
// you have to do this locally as well as on the parse server by updating
// the PFInstallation object
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.