且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

未找到更新错误 Parse Swift 的对象

更新时间:2022-03-12 09:37:33

尝试将您的保存代码更改为:

Try changing your save code to this:

    requested = PFObject(className: "Request")
    requested!["From"] = PFUser.currentUser()
    requested!["FromUsername"] = PFUser.currentUser()?.username
    requested!["ToUsername"] = user
    requested!["To"] = newFriend
    requested!["Approve"] = true
    requested.ACL?.setPublicWriteAccess(true)
     requested!.saveInBackgroundWithBlock {(success: Bool, error: NSError?) -> Void in
        if error == nil {
           print("success")
        }
        else{
            print(error)
        }
    }

行:

 ACL?.setPublicWriteAccess(true)

将设置它以便任何人都可以编辑对象.这可能不是您想要的.还有其他方法可以允许某人覆盖对象.您可以根据自己的需要以及 Parse 后端的配置方式来使用它们:

will set it so anyone can edit to the object though. That may not be exactly what you want. There are other methods too that can allow someone to write over an object. You may be able to use them depending on your needs and how your Parse backend is configured:

    object.ACL?.setWriteAccess(allowed: Bool, forRole: PFRole)
    object.ACL?.setWriteAccess(allowed: Bool, forRoleWithName: String)
    object.ACL?.setWriteAccess(allowed: Bool, forUser: PFUser)
    object.ACL?.setWriteAccess(allowed: Bool, forUserId: String)

另请注意,这不适用于解析中的当前对象.仅适用于添加 setWriteAccess 方法后保存的对象.如果要在解析中编辑当前对象,则必须手动更改数据库本身的读写权限.

Also note that this will not work for current objects in parse. Only for objects saved after adding the setWriteAccess method. If you want to edit current objects in parse, you have to change the read and write permissions form the database itself, manually.