ios - 使用allowDeferredLocationUpdatesUntilTraveled 时是否可能出现乱序didUpdateLocations

标签 ios gps core-location cllocationmanager cllocation

我已将 [CLLocation allowedDeferredLocationUpdatesUntilTraveled: timeout] 添加到我的应用中。大多数时候一切正常。当我打开屏幕时,我会时不时地在延迟位置的中间获取当前位置。位置管理器是否有可能向我的应用程序发送当前位置的 locationManager:didUpdateLocations: ,然后使用一组延迟位置来调用它?关于传递给 locationManager:didUpdateLocations Apple 文档的位置

This array always contains at least one object representing the current location. If updates were deferred or if multiple locations arrived before they could be delivered, the array may contain additional entries. The objects in the array are organized in the order in which they occurred. Therefore, the most recent location update is at the end of the array.

我没有看到任何有关 didUpdateLocations 调用顺序的信息。是否能保证以正确的顺序调用委托(delegate)方法 didUpdateLocations?

谢谢!

斯蒂芬

最佳答案

所以我在developer.apple.com ( https://devforums.apple.com/thread/251363?tstart=0 ) 上找到了这个问题的答案。基本上,是的,这可能会发生。当设备唤醒时,它首先发送您当前位置的一些单独位置,然后发送延迟位置。这与我看到的行为相符。以下是来自developer.apple.com 的回复。

I was "sanitising" the time stamps so that my subsequent code would not be confused by time going backwards. I thought I had allowed for this in deferred mode by sorting the batch of deferred locations by time stamp on receipt, but actually I wasn't doing enough. What actually seems to happen when the device wakes after a deferred period is that it sends a handful of individual locations first, with the current time stamp, and then sends the large batch of saved GPS fixes. So the lesson is that if you're going to try to sort your location fixes you need to process more than just a single deferred batch. You really need to merge the new locations into your previously-received locations, going back as far as necessary. it's unfortunate that deferred mode is so difficult to debug.

关于ios - 使用allowDeferredLocationUpdatesUntilTraveled 时是否可能出现乱序didUpdateLocations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26889834/

相关文章:

ios - 将 HKSample 与另一个 HKSample 进行比较以防止重复

ios - SQL.swift 从多个表中选择

java - 如何将 GPS 坐标从一部 Android 手机发送到另一部?

android - 带有 GPS 位置的 mp4 视频文件

iphone - iOS 检测连接速度或类型

ios - NSCFData 压缩数据崩溃

java - 使用android studio获取两点之间的旅行时间的问题

ios - 终止/暂停时显着更改位置 API 的行为?

swift - 利用Core Location获取坐标并计算谁是100米圆翼

swift - 使用 MVVM-Pattern 处理 SwiftUI 和 CoreLocation