func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// Set up the Parse SDK
let configuration = ParseClientConfiguration {
$0.applicationId = "WhatsTheHW"
$0.server = "https://whatsthehw-parse-alan.herokuapp.com/parse"
}
Parse.initializeWithConfiguration(configuration)
let query = PFQuery(className: "Course")
query.findObjectsInBackgroundWithBlock {(result: [PFObject]?, error: NSError?) -> Void in
for object in result! {
// existing objectIds: 1Ja2Hx77zA, 34AF1vKO6f, 5FWlsswxw0
if object.objectId == "34AF1vKO6f" {
object["studentRelation"] = ["hi", "ih"]
object.saveInBackgroundWithBlock{(success, error) in
if success == true {
print("\(object) saved to parse")
} else {
print("save failed: \(error)")
}
}
}
}
}
return true
}
这是我可以将此任务减少到的最低限度(此代码位于 AppDelegate)。
当我尝试在解析仪表板中使用 REST api 和 api 控制台时一切正常,但它不适用于 iOS sdk。
我从打印语句中得到的错误是
Error Domain=Parse Code=101 "Object not found." UserInfo={code=101, temporary=0, error=Object not found., NSLocalizedDescription=Object not found.}
如果我只是像这样添加一个新对象,它就可以工作:
let object = PFObject(className: "Course")
object["name"] = "German"
object["studentRelation"] = ["a", "b"]
object.saveInBackgroundWithBlock{(success, error) in
if success == true {
print("save completed")
print("\(object) saved to parse")
} else {
print("save failed: \(error)")
}
}
我真的迷路了,我不知道为什么会这样。
提前致谢。
最佳答案
此问题可能与您尝试保存的对象的访问权限 (ACL
) 有关。 [Error]: Object not found
当一个没有 write
访问对象的用户试图保存它时打印,Parse SDK 的错误消息真的是此处误导!
确保尝试保存该对象的解析用户具有正确的写入权限,以便在您的解析数据库中实际写入该对象。
一个简单的解决方法是将应用内的默认 ACL
设置为 public read + write
:
let acl = PFACL()
acl.publicReadAccess = true
acl.publicWriteAccess = true
PFACL.setDefaultACL(acl, withAccessForCurrentUser: true)
但请谨慎使用此方法,通常您希望根据用户的实际角色设置访问权限。因此,更好的替代方法是在创建 PFObject
时仅设置 ACL
,并且只向您授予 write
访问权限的用户知道应该能够改变对象。
关于ios - 在 Parse iOS 中更新对象,[错误] : Object not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38799580/