gpt4 book ai didi

swift - CLLocationManager.requestLocation 调用它的委托(delegate)需要多长时间

转载 作者:行者123 更新时间:2023-11-30 10:44:28 25 4
gpt4 key购买 nike

我们收到一份报告,其中一些用户被困在我们应用的某些屏幕中,无法继续访问应用的仪表板。

检查有问题的屏幕后,发现这是一个“正在加载”屏幕,将在用户成功登录后显示。唯一可能导致用户卡在此处的代码是 CLLocationManager。屏幕将等待 CLLocationManager 调用 didUpdateLocations 或 didFailWithError,然后进入应用程序的仪表板。

我的猜测是 CLLocationManage 没有调用它的任何委托(delegate)。因此,用户被困在“加载”屏幕中。

CLLocationManager.requestLocation 调用其委托(delegate)函数需要多长时间?如果请求时间太长,CCLocationManager 会调用 didFailWithError 吗?

以下是我们代码的缩短版本:

override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestLocation()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
// process the location then forward to dashboard screen
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
// forward to dashboard screen
}

非常感谢任何信息! TIA!

最佳答案

如果您使用startUpdatingLocation(),通常需要大约一秒钟才能获得第一次更新。第一次更新通常是旧的(缓存的)位置,但很快就会到达。

使用 requestLocation() 可能会花费几秒钟的时间,因为它将等待直到找到一个合适的位置。

This method returns immediately. Calling it causes the location manager to obtain a location fix (which may take several seconds) and call the delegate’s locationManager(_:didUpdateLocations:) method with the result. The location fix is obtained at the accuracy level indicated by the desiredAccuracy property. Only one location fix is reported to the delegate, after which location services are stopped.

您的问题是您没有在位置管理器上调用requestWhenInUseAuthorization()。您必须获得使用位置的许可。除了调用该函数之外,您还需要执行一些其他操作(将键添加到应用程序的 Info.plist)。

关于swift - CLLocationManager.requestLocation 调用它的委托(delegate)需要多长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56053643/

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