简体   繁体   中英

PFUser currentUser returns nil

I'm using Parse SDK, login and signup are working perfectly : [PFUser currentUser] is returning the current user.

But after restarting app, [PFUser currentUser] is returning nil.

Why is the application not persisting the session ?

Login code (from parse.com) I'm using :

[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. I don't know how and why, but it works.

EDIT: There is no logout in the whole project

在此处输入图片说明

It looks like you are calling .logout somewhere, in which case the app will return nil for [PFUser currentUser] .

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
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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