简体   繁体   English

使用Xcode 8和Swift 3在解析中更新用户位置

[英]Update User Location In Parse Using Xcode 8 and Swift 3

I am running Parse Server and trying to log a user in and then update their location . 我正在运行Parse Server并尝试登录用户,然后更新其位置 Right now I am just manually creating a PFGeoPoint and then trying to add it to the key " location " which I have already added on Parse Server as a PFGeoPoint. 现在,我只是手动创建一个PFGeoPoint ,然后尝试将其添加到我已经作为PFGeoPoint在Parse Server上添加的键“ location ”中。 When I run the following code I receive an error. 当我运行以下代码时,我收到一个错误。

 let currentUser = PFUser.logInWithUsername(inBackground: "test", password: "test")
 let point = PFGeoPoint(latitude: 25.000, longitude: 25.000)
 currentUser.setValue(point, forKey:"location")

The error is as follows: 错误如下:

'NSUnknownKeyException', reason: '[<BFTask 0x60000067da00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key location.'

How can I resolve this error? 如何解决此错误? Any help would be much appreciated! 任何帮助将非常感激! I am using Xcode 8 and Swift 3. 我正在使用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) 
          } 
 }

here is method that is use for find the user current location and pass that data to your server with your PFGeoPoint that task is perform in Background. 这是用于查找用户当前位置并将该数据与PFGeoPoint一起传递到服务器的方法,该任务在后台执行。 here i also mention that if your location changes or get it so in server PFUser update their location with new one . 在这里我还提到,如果您的位置发生更改或在服务器PFUser中得到它,请使用新的位置更新其位置。 hope you are little clear about this. 希望您对此不太清楚。

thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM