【问题标题】:Error Domain=Parse Code=209 "The operation couldn’t be completed错误域=解析代码=209“操作无法完成
【发布时间】:2015-03-26 08:07:54
【问题描述】:

我安装了 ParseStarterProject swift 版本并使用以下代码创建了一个新用户:

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

然后我再次运行该项目,我收到以下错误:

2015-03-26 09:49:25.485 ParseStarterProject[14768:199520] [错误]:无效会话令牌(代码:209,版本:1.7.0) 2015-03-26 09:49:25.489 ParseStarterProject [14768:199521] [错误]:最终无法运行命令并出现错误:错误域 = 解析代码 = 209“操作无法完成。(解析错误 209。) " UserInfo=0x7fcda3cb6680 {error=invalid session token, code=209}

我做错了什么??

【问题讨论】:

    标签: ios iphone swift parse-platform


    【解决方案1】:

    我认为获取当前用户也会执行登录,但事实并非如此。 所以问题是我试图在不执行登录的情况下保存一个对象。

    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")
            }
    
        }
    }
    

    【讨论】:

    • PFUser.currentUser() 将在用户未登录时返回 nil。您只需要在它为 nil 的情况下执行登录(在 if 语句中添加 else 块)。跨度>
    猜你喜欢
    • 2014-11-02
    • 2018-12-16
    • 2017-07-09
    • 2015-07-13
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多