Ala*_*Lee 5 ios parse-platform swift
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
}
Run Code Online (Sandbox Code Playgroud)
这是我可以将此任务减少到的最小值(此代码位于 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.}
Run Code Online (Sandbox Code Playgroud)
如果我只是像这样添加一个新对象,它会起作用:
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)")
}
}
Run Code Online (Sandbox Code Playgroud)
我真的很迷茫,我不知道为什么会这样。
提前致谢。
此问题可能与您尝试保存的对象的访问权限( )有关。当无权访问对象的用户尝试保存它时,会打印此错误消息,Parse SDK 的错误消息在这里确实具有误导性!ACL[Error]: Object not foundwrite
确保尝试保存对象的解析用户具有正确的写入权限,可以在解析数据库中实际写入该对象。
一个简单的解决方法是将ACL应用程序内的默认设置设置为public read + write:
let acl = PFACL()
acl.publicReadAccess = true
acl.publicWriteAccess = true
PFACL.setDefaultACL(acl, withAccessForCurrentUser: true)
Run Code Online (Sandbox Code Playgroud)
但要小心这种方法,通常您希望根据用户的实际角色设置访问权限。因此,更好的选择是仅在创建对象时设置ACLon ,并且仅向您知道应该能够更改对象的用户授予访问权限。PFObjectwrite
| 归档时间: |
|
| 查看次数: |
722 次 |
| 最近记录: |