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.
我从print语句得到的错误是
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)有关. [错误]:当没有对象的写入权限的用户试图保存它时,打印未找到对象,Parse SDK的错误消息在这里真的是误导!
确保尝试保存对象的解析用户具有正确的写入以实际写入解析数据库中的该对象.
一个简单的解决方法是将应用程序内的默认ACL设置为公共读写:
let acl = PFACL()
acl.publicReadAccess = true
acl.publicWriteAccess = true
PFACL.setDefaultACL(acl, withAccessForCurrentUser: true)
但要注意这种方法,通常要根据用户的实际角色设置访问权限.因此,更好的选择是在创建PFObject时仅在PFObject上设置ACL,并且只向您知道应该能够更改对象的用户提供写访问权限.