【发布时间】:2020-01-29 16:21:06
【问题描述】:
我从 iOS 9 开始一直在使用后台位置更新,没有任何问题,而这个问题现在刚刚出现在 iOS 13 中。当应用程序进入后台时,调试器控制台会识别出这个问题:“无法结束 BackgroundTask:没有背景任务存在标识符为 3 (0x3),或者它可能已经结束。中断 UIApplicationEndBackgroundTaskError() 以进行调试。"
以下是在后台更新位置的样板代码:
一、AppDelegate中的代码:
if CLLocationManager.authorizationStatus() == .notDetermined {
locationManager.requestAlwaysAuthorization()
locationManager.allowsBackgroundLocationUpdates = true
}
info.plist:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>"MY APP" is optimized to run in the background as well as when your using it directly. For best results, choose ALWAYS.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>"MY APP" is optimized to run in the background. Please choose ALLOW.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Please choose ALLOW WHILE USING APP. "MY APP" needs to use your location to get its altitude data.</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
据我所知,没有什么应该导致这个问题。为什么它才刚刚开始是没有意义的。
【问题讨论】:
-
尽管有一个在后台不执行任何操作的应用程序,但我还是收到了这条消息。 AFAICT,这是某种 iOS 13 问题。不过,它似乎并没有造成任何问题(除了烦人之外),也没有阻止应用通过审核。
-
我想更大的问题是位置更新正在后台停止,我必须调试的唯一信息是控制台消息。