繁体   English   中英

PFUser currentUser返回nil

[英]PFUser currentUser returns nil

我正在使用Parse SDK,登录和注册工作正常: [PFUser currentUser]返回当前用户。

但是重新启动应用程序后, [PFUser currentUser]返回nil。

为什么应用程序不保留会话?

登录代码(来自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.
                                    }
                                }];

编辑2:创建新项目,它可以工作。 我不知道如何以及为什么,但是可以。

编辑:整个项目中没有logout

在此处输入图片说明

似乎您在某处调用.logout ,在这种情况下,该应用将为[PFUser currentUser]返回nil

如果您没有自动注销该用户,则当前用户将在会话之间保持不变。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM