0
votes

I installed the ParseStarterProject swift version and created a new user with the following code:

var user = PFUser()
...
user.signUpInBackgroundWithBlock...

Then I ran the project again and I get the following errors:

2015-03-26 09:49:25.485 ParseStarterProject[14768:199520] [Error]: invalid session token (Code: 209, Version: 1.7.0) 2015-03-26 09:49:25.489 ParseStarterProject[14768:199521] [Error]: Failed to run command eventually with error: Error Domain=Parse Code=209 "The operation couldn’t be completed. (Parse error 209.)" UserInfo=0x7fcda3cb6680 {error=invalid session token, code=209}

what have I done wrong??

1

1 Answers

0
votes

I thought getting the current user also performs login but it does not. So the problem was that I was trying to save an object without performing login.

func login() {
    var username = username from UI or key store
    var password = password from UI or key store
    if let currentUser = PFUser.currentUser() {
        println("current user is \(currentUser.username)")
        username = currentUser.username
    }
    PFUser.logInWithUsernameInBackground(username, password:password) {
        (user: PFUser!, error: NSError!) -> Void in
        if user != nil {
            println("successful login with \(user.username)")
            self.saveSomething()
        } else {
            println("failed login with \(user.username)")
        }
    }

}

func saveSomething() {
    var gameScore = PFObject(className:"GameScore")
    gameScore["score"] = 1337
    gameScore["playerName"] = "Sean Plott"
    gameScore["cheatMode"] = false
    gameScore.saveInBackgroundWithBlock {
        (success: Bool, error: NSError!) -> Void in
        if (success) {
            println("The object has been saved")
        } else {
            println("There was a problem, check error.description")
        }

    }
}