![enter image description here](https://istack.dev59.com/1S0nj.webp)
let locationManager = CLLocationManager()
open override func viewDidLoad() {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 10
locationManager.allowsBackgroundLocationUpdates = true
locationManager.startUpdatingLocation()
}
open func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let notification = UILocalNotification()
notification.alertBody = "location updated"
notification.fireDate = Date()
UIApplication.shared.scheduleLocalNotification(notification)
}
我设置了NSLocationAlwaysUsageDescription
字符串并请求权限。当应用程序第一次加载时,用户授予始终使用的权限。
当应用程序在前台时,它运行良好,在后台时仍然有效,至少在5-40分钟的时间范围内,这取决于电池或其他已打开的应用程序而有所改变。
问题是为什么它停止工作,难道不应该保持工作状态吗?
我从未在Apple文档中看到过时间限制。
requestAlwaysAuthorization()
,对吧? - Ahmad F