【问题标题】:How to avoid gaps in gps tracking on iOS 11如何在 iOS 11 上避免 GPS 跟踪中的空白
【发布时间】:2018-03-11 17:46:17
【问题描述】:

我在跟踪应用程序中遇到问题,但仅限于 iOS 11。该应用程序会在特定条件下在后台被动记录您的 GPS 位置。

在 iOS 11 上出现的问题是 CLLocationManager 似乎随机停止报告 GPS 事件 10 到 900+ 秒。

位置管理器的设置如下:

    let locationManager = CLLocationManager()
    locationManager.allowsBackgroundLocationUpdates = true
    locationManager.pausesLocationUpdatesAutomatically = false
    locationManager.startMonitoringSignificantLocationChanges()
    locationManager.desiredAccuracy = 10
    locationManager.activityType = .automotiveNavigation

认为 CoreLocation 为所有回调管理和使用的线程可能负担过重。

我已尝试委派给不同的线程进行处理,因此该应用不会占用 CoreLocations 资源。这是使用如下设置的操作队列完成的:

    let queue = OperationQueue()
    queue.maxConcurrentOperationCount = 1
    queue.qualityOfService = .userInitiated

使用该操作队列进行回调:

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        queue.addOperation {
            // process locations
        }
    }

引入操作队列并没有帮助避免间隙,但它确实做到了,当间隙发生时,位置管理器会报告一堆(不同的)具有相同时间戳的位置。

具有相同时间戳的位置并不是所有丢失的位置,即如果有 200 秒的间隙,我可能只会得到 15 个具有相同时间戳的位置。

我希望这里有人能告诉我为什么会发生这种情况以及我可以做些什么来避免这些差距。

提前致谢。

【问题讨论】:

  • 您是否有幸找到有关此问题的更多信息?自 iOS 11 发布以来,我们的应用程序中遇到了类似的问题,而且关于该主题的讨论似乎很少。
  • 我也遇到了同样的问题,你解决了这个问题吗?

标签: ios gps cllocationmanager ios11


【解决方案1】:

经过多次审查、试验、与 Apple 的讨论,我们现在似乎已经解决了这个问题。即使Apple仅在跟踪开始时应用程序在前台时才保证GPS跟踪后台。我们应用的修复正在更改以下内容:

        locationManager.startMonitoringSignificantLocationChanges()

...到:

        locationManager.stopMonitoringSignificantLocationChanges()
        locationManager.startMonitoringSignificantLocationChanges()

理论上是,在启动期间将 true 应用于“监控”设置时,应用程序的设置会损坏。如果首先将“监控”设置设置为 false,然后再设置为 true,则不会发生损坏。

此修复程序已在数百人的应用商店应用程序中进行,并且后台跟踪工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 2014-10-13
    • 2016-03-08
    • 1970-01-01
    相关资源
    最近更新 更多