我的应用在使用中和在后台运行时需要频繁更新位置。
我已启用后台模式 --> 我的应用程序的位置更新,但我的应用程序在进入后台模式后约 10 秒停止接收位置更新。
我的代码:
func initializeLocationManager()
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.distanceFilter = 1
}
func startLocationManager()
{
locationManager.startUpdatingLocation()
}
我还在 info.plist 中添加了以下内容:
NSLocationAlwaysUsageDescription
如有任何帮助,我们将不胜感激。
谢谢。
最佳答案
这解决了我的问题:
if #available(iOS 9.0, *) {
locationManager.allowsBackgroundLocationUpdates = true
} else {
// Fallback on earlier versions
}
关于iOS 应用程序在后台时无法接收位置更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33752758/