使用Swift IOS8在Parse.com中更新用户 [英] Updating user in Parse.com using Swift IOS8
问题描述
我试图通过在解析中创建的objectId来吸引用户. 之后,通过增加特定键来更新该对象.在这种情况下是投票"
I am trying to get a user by objectId created in parse. After that, update that object by incrementing particular key. in this case "votes"
我尝试了以下代码,并成功获取了对象,然后将其转换为PFUser
进行更新,但是在后台保存期间抛出错误,声称用户必须登录或注册,但已经拥有该对象该用户?
I have tried the following code, and it succesfully gets the object then cast it to PFUser
for updating but it throws an error during save in background claiming that the user has to be logged in or signed up yet it already has that user?
感谢您的帮助.
var sender = self.mObject["sender"] as PFUser
var senderObjId = sender.objectId
println(senderObjId) //prints sender user object id
//query the user
var query = PFUser.query()
query.getObjectInBackgroundWithId(senderObjId, block: { (object: PFObject!, error: NSError!) -> Void in
let user : PFUser = object as PFUser
user.incrementKey("votes")
user.saveEventually({ (success: Bool!, error: NSError!) -> Void in
println(success)
})
})
收到特定错误:
"NSInternalInconsistencyException" with reason "User cannot be saved unless `they have been authenticated via logIn or signUp":`
推荐答案
您没有使用要编辑的帐户登录. 您只能编辑当前帐户,而不能编辑PFUser表中的任何帐户. 这就是我在分析中发现的:
You're not logged in with the account which you want to edit. You can only edit the current account and not any account in the PFUser table. That's what I found on parse:
用户对象的安全性
Security For User Objects
默认情况下,PFUser类是安全的. PFUser中存储的数据可以 只能由该用户修改.默认情况下,仍可以读取数据 由任何客户.因此,某些PFUser对象已通过身份验证,可以通过 修改,而其他则为只读.
The PFUser class is secured by default. Data stored in a PFUser can only be modified by that user. By default, the data can still be read by any client. Thus, some PFUser objects are authenticated and can be modified, whereas others are read-only.
具体来说,您将无法调用任何保存或删除操作 除非PFUser是使用经过身份验证的方法获得的,否则, 如logIn或signUp.这样可以确保只有用户才能更改他们的 自己的数据.
Specifically, you are not able to invoke any of the save or delete methods unless the PFUser was obtained using an authenticated method, like logIn or signUp. This ensures that only the user can alter their own data.
请参见此如何登录.
这篇关于使用Swift IOS8在Parse.com中更新用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!