PFUser currentUser返回nil

时间:2015-08-12 11:10:48

标签: ios objective-c parse-platform pfuser

我使用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

enter image description here

2 个答案:

答案 0 :(得分:0)

您似乎在某个地方呼叫.logout,在这种情况下,应用会为nil返回[PFUser currentUser]

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

答案 1 :(得分:0)

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
    }
相关问题