gpt4 book ai didi

ios - 为当前用户更新解析对象而不是创建重复条目

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:34 25 4
gpt4 key购买 nike

我正在尝试让用户更新他们的位置。当我尝试保存数据时,它会创建一个重复条目而不是更新旧信息。我有一个部署到 mongolabs 数据库的 heroku 解析服务器。

class DropLoc: UIViewController, CLLocationManagerDelegate { 

var user = PFUser.currentUser()
var post = PFObject(className:"Post")
var query = PFQuery(className:"Post")
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()

}
}
}

最佳答案

看起来 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com