我们的应用程序在后台模式下使用位置跟踪,但在最小化“applicationwillterminate:”方法后,会在 20 到 50 分钟后调用。它只是有时发生,而不是每次发生。
最佳答案
使用 expiration handler 的后台任务。检查backgroundTimeRemaining
并在获取位置数据时调用 endBackgroundTask(_:)
。
If you do not end your tasks in a timely manner, the system terminates your app.
按照 Updating Your App with Background App Refresh 中所述使用后台任务,伺机更新数据。
关于支持位置跟踪的后台模式的 iOS 应用程序会在一段时间后自动关闭(并非在每个 session 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56886314/