对于我的应用程序,用户可以更改他们当前的用户名。所以使用parse,我为当前用户设置了新的用户名,如下面的代码所示。然后,我调用saveInBackgroundWithBlock来保存新用户名。然而,我得到了这个错误“用户名已经被占用”。但是现在,即使保存失败,PFUser.currentUser.username也被设置为无效的新用户名。我给fetch打了电话,但这并没有改变任何事情。如何更新PFUser.currentUser
let user = PFUser.currentUser()
user.username = newUsernameText
user.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
self.helper.successAlert("Saved!", msg: "Your profile has been updated.")
} else {
// There was a problem, check error.description
self.helper.errorAlert("Error", msg: (error?.localizedDescription)!)
PFUser.currentUser().fetch()
self.user = PFUser.currentUser()
print(user.username) //prints the new username that was invalid
}
}发布于 2015-12-06 04:35:03
尝试将用户名更改为完全不同的名称。有可能您的数据库中已经有该用户名。另一种方法是首先查询所有现有用户,然后检查用户名是否使用了if-else语句。如果它没有更新,如果它正在抛出警报。干杯
https://stackoverflow.com/questions/34110431
复制相似问题