我的應用程序,用戶可以改變他們的當前用戶名。所以使用解析,我爲下面我的代碼中顯示的當前用戶設置新的用戶名。然後我撥打saveInBackgroundWithBlock
保存新的用戶名。但是,我收到了這個錯誤「用戶名已被佔用」。但現在PFUser.currentUser.username
設置爲無效新用戶名,即使保存失敗。我打電話fetch
,並沒有改變任何東西。我如何更新PFUser.currentUser
?更新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
}
}
我想,'打印(user.username)'引用您的本地範圍'user' ...怎麼樣'打印(self.user.username)'或'打印(PFUser.currentUser()。用戶名)'? – Alladinian
PFUser.currentUser.username也返回無效的新的用戶名 – learningthings
嘗試用戶[「用戶名」] = newUsernameText –