我正在运行Parse Server并尝试登录用户,然后更新其位置。现在,我只是手动创建一个PFGeoPoint,然后尝试将其添加到我已经作为PFGeoPoint在Parse Server上添加的键“ location ”中。当我运行以下代码时,我收到一个错误。
let currentUser = PFUser.logInWithUsername(inBackground: "test", password: "test")
let point = PFGeoPoint(latitude: 25.000, longitude: 25.000)
currentUser.setValue(point, forKey:"location")
错误如下:
'NSUnknownKeyException', reason: '[<BFTask 0x60000067da00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key location.'
如何解决此错误?任何帮助将非常感激!我正在使用Xcode 8和Swift 3。
PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, error: NSError?) -> Void in
if error == nil {
print("got location successfully")
PFUser.currentUser()!.setValue(geoPoint, forKey:"location") PFUser.currentUser()!.saveInBackground()
} else {
print(error)
}
}
这是用于查找用户当前位置并将该数据与PFGeoPoint一起传递到服务器的方法,该任务在后台执行。在这里我还提到,如果您的位置更改或在服务器PFUser中获取,请使用新的位置更新其位置。希望您对此不太清楚。
谢谢你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句