是否可以在 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/