我很难更新Kinvey上已注册的用户。
例如,如果我使用此代码注册新用户:
KCSUser.userWithUsername(
"kinvey",
password: "12345",
fieldsAndValues: [
KCSUserAttributeEmail : "kinvey@kinvey.com",
KCSUserAttributeGivenname : "Arnold",
KCSUserAttributeSurname : "Kinvey"
],
withCompletionBlock: { (user: KCSUser!, errorOrNil: NSError!, result: KCSUserActionResult) -> Void in
if errorOrNil == nil {
//was successful!
let alert = UIAlertView(
title: NSLocalizedString("Account Creation Successful", comment: "account success note title"),
message: NSLocalizedString("User created. Welcome!", comment: "account success message body"),
delegate: nil,
cancelButtonTitle: NSLocalizedString("OK", comment: "OK")
)
alert.show()
} else {
//there was an error with the update save
let message = errorOrNil.localizedDescription
let alert = UIAlertView(
title: NSLocalizedString("Create account failed", comment: "Create account failed"),
message: message,
delegate: nil,
cancelButtonTitle: NSLocalizedString("OK", comment: "OK")
)
alert.show()
}
}
)
我如何更新KCSUserAttributeGivenname或KCSUserAttributeSurname。
任何帮助将不胜感激。谢谢
答案 0 :(得分:0)
我已经找到了如何成功更新用户的方法。它看起来像这样:
KCSUser.activeUser().setValue("John", forAttribute: "first_name")
KCSUser.activeUser().setValue("Doe", forAttribute: "last_name")
然后,您只需调用.refreshFromServer来更新服务器,然后调用.saveWithCompletionBlock以将更新后的更改保存到后端。