swift - 位置管理器上的计时器

标签 swift timer cllocationmanager

是否可以在 Timer 中调用 didUpdateLocations?我的意思是..

_timer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(_:didUpdateLocations:)), userInfo: nil, repeats: true) 

那行得通吗?如果是,那么它将每 10 秒更新一次位置?

最佳答案

您不能调用 didUpdateLocations。如果您想要频繁更新,最好的选择是标准位置服务:

The standard location service is most appropriate for apps that deliver location-related information directly to the user but it may be used by other types of apps too. To start the service, configure the desiredAccuracy and distanceFilter properties of the location manager and then call the requestLocation(), startUpdatingLocation(), or allowDeferredLocationUpdates(untilTraveled:timeout:) method. Never specify an accuracy value greater than what you need. Core Location uses the accuracy value you specify to manage power better. A higher degree of accuracy requires more precise hardware like GPS, which consumes more power.

https://developer.apple.com/reference/corelocation/cllocationmanager

关于swift - 位置管理器上的计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41981255/

相关文章:

java - 如何每天下午 2 点运行 TimerTask?

ios - 为什么 CLLocationManager 不传递事件来处理?

swift - 具有多个数组的 TableView segue

python - pygame.time.set_timer 困惑?

c# - 如何以编程方式触发计时器滴答?

iphone - didUpdateLocations 会在稳定手机上调用还是现在调用?

ios - 位置更新问题 iOS

ios - 单元格标签无法捕获表格 View 中的值

ios - 如何判断 UIViewController 是第一次启动?

swift - self 协议(protocol)的行为