简体   繁体   中英

iOS Swift + Parse.com - user authentication best practices

I would love to know if there are some best practices out there to prevent me from future frustration when it comes to user authentication with Parse.com in Swift projects.

I have a handful of Views that would not function without a logged in user. My current methodology has been to use ViewWillAppear to redirect non-loggedin users to the login page with something as simple as

override func viewWillAppear(animated: Bool) {
    if (PFUser.currentUser() == nil) {   
         self.navigationController?.popToRootViewControllerAnimated(true)
         presentViewController(alert, animated: true, completion: nil
    } else {
        // (...code...)
}

but occasionally i get a parse 209 error : invalid session token when somehow i login a user in the iOS simulator but parse doesn't recognize that user as the current user on the server side. I'd love to know if I'm following solid conventions or just making up weird workarounds that are causing externalities.

A few comments:

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