繁体   English   中英

对于获取位置 didUpdateLocations 没有击中真正的设备 swift

[英]For getting location didUpdateLocations is not hitting on real devcie swift

我需要获取当前位置,但是当我允许位置访问并运行代码时,它没有点击 didUpdateLocations 方法,而是点击了 iphone 6 上的 didFailWithError。我还在 plist 中添加了所需的详细信息。 请帮助我调试问题是否在我的代码中。

这是代码

 func determineCurrentLocation() {
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        if CLLocationManager.locationServicesEnabled() {
          locationManager.startUpdatingLocation()
        }
    }
   
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print(manager.location!.coordinate)
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("Location data not enabled")
    }

在 plist 中,我添加了隐私-始终位置和使用时使用说明隐私-使用时位置使用说明

这是打印的错误 Error Domain=kCLErrorDomain Code=0 "(null)"

CLLocationManager.locationServicesEnabled()表示在设备上启用了位置服务,而不是用户授权使用它。

使用CLLocationManager.authorizationStatus()检查授权,并最终要求用户给予授权。

暂无
暂无

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

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