我试图让用户更新他们的位置。当我尝试保存数据时,它会创建一个重复条目,而不是更新旧信息。我有一个部署到 mongolabs 数据库的 heroku 解析服务器。
class DropLoc: UIViewController, CLLocationManagerDelegate {
var user = PFUser.currentUser()
var post = PFObject(className:"ost")
var query = PFQuery(className:"ost")
var point: PFGeoPoint!
let porta = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
var curGate = porta.location
self.porta.delegate = self
self.porta.desiredAccuracy = kCLLocationAccuracyBest
self.porta.requestWhenInUseAuthorization()
self.porta.startUpdatingLocation()
point = PFGeoPoint(location: curGate)
query.whereKey("user", equalTo: user!)
query.findObjectsInBackgroundWithBlock {(objects: [PFObject]?, error: NSError?) -> Void in
if error != nil {
print(error)
}else{
self.post["user"] = self.user ?? NSNull()
self.post["location"] = self.point ?? NSNull()
self.post.saveInBackground()
}
}
}
}
Best Answer-推荐答案 strong>
看来 point 只设置了一次。尝试从 CLLocationManagerDelegate 添加以下方法协议(protocol)。
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
// updated coordinate
point = PFGeoPoint(location: manager.location!)
}
关于ios - 更新当前用户的解析对象而不是创建重复条目,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/38816863/
|