gpt4 book ai didi

swift - startMonitoringSignificantLocationChanges() 在物理设备上不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 06:57:16 27 4
gpt4 key购买 nike

当 locationManager 设置为 startMonitoringSignificantLocationChanges() 时,我无法在物理设备上显示位置。

模拟器中一切正常,但当我让它在我的 iPhone 上运行时,没有返回坐标,如果我将它更改为 startUpdatingLocation(),它就可以在我的物理设备上运行。

知道哪里出了问题吗?

我的代码:

  let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()

startReceivingSingificantLocationChanges()
}

func startReceivingSingificantLocationChanges() {

if !CLLocationManager.significantLocationChangeMonitoringAvailable() {
//the service is not available
print("Service is not available")
return
}

locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startMonitoringSignificantLocationChanges()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first{
print(location.coordinate)
coordinatesLbl.text = "LAT:\(location.coordinate.latitude) LONG:\(location.coordinate.longitude)"
}
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == CLAuthorizationStatus.denied{
showLocationDisabledPopUp()
print("didChangeAuthorization")
}
}

最佳答案

The documentationstartMonitoringSignificantLocationChanges() 状态下:

Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

因此,在使用此方法时,您不应该经常期望它们。

startUpdatingLocation 更频繁地更新,这就是它起作用的原因。

关于swift - startMonitoringSignificantLocationChanges() 在物理设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52832040/

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