当我运行我的应用程序时,它不会注册用户位置,但是当我在调试器中更改位置时,它将开始正常注册

shadyelkassas77

当我第一次运行该应用程序时,它不会自动获取用户位置,因此我必须在调试器中手动添加该位置,然后对其进行注册。

    func viewDidLoad() {
    super.viewDidLoad()
    //permissions, in ViewDidLoad()
    self.locationManager.requestAlwaysAuthorization()
    self.locationManager.requestWhenInUseAuthorization()

    if CLLocationManager.locationServicesEnabled(){
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
        locationManager.pausesLocationUpdatesAutomatically = false
    }



func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let _ : CLLocationCoordinate2D = manager.location?.coordinate else{
        return
    }

    geoFire!.setLocation(locations.last!, forKey: Auth.auth().currentUser!.uid)

    InRange(location: locations.last!)

    for ids in keysInCircle{
        fetchInformation(idlabel: ids)
    }

}
亚瑟·戴夫

可能是因为您没有在设置location的任何其他属性之前开始更新位置。您应该首先调用“ startUpdatingLocation()”函数。

尝试按照以下说明更改代码。

if CLLocationManager.locationServicesEnabled() {
    locationManager.delegate = self
    locationManager.startUpdatingLocation()

    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.pausesLocationUpdatesAutomatically = false

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章