更新时间:2022-12-26 12:53:39
我在 Apple 开发者论坛的帮助下找到了解决方案:
I found a solution to implement this with the help of the Apple Developer Forums:
定位背景模式
UIApplication:beginBackgroundTaskWithExpirationHandler:
NSTimer
n
smaller 比 UIApplication:backgroundTimeRemaining
时,它会正常工作.当 n
larger 时,location manager
应该在没有剩余时间之前再次启用(和禁用)以避免后台任务被杀死.location background mode
NSTimer
in the background with UIApplication:beginBackgroundTaskWithExpirationHandler:
n
is smaller than UIApplication:backgroundTimeRemaining
it will work just fine. When n
is larger, the location manager
should be enabled (and disabled) again before there is no time remaining to avoid the background task being killed. 这是可行的,因为位置是三种允许的后台执行类型之一.
注意:我在模拟器中测试它而浪费了一些时间,但它不起作用.但是,它在我的手机上运行良好.