ios 9 应用程序不在后台报告位置

标签 ios swift core-location

我正在(用 Swift 编写)一个 iOS 9 应用程序,它需要位置更新,包括在后台模式下。问题是我只能在前台获取位置更新。我想我做的一切都是正确的:

在 info.plist 中:

  • 为 NSLocationAlwaysUsageDescription 指定了一个值。

  • 为 NSLocationUsageDescription 指定了一个值。

  • 为 NSLocationWhenInUseUsageDescription 指定了一个值。

  • 在 UIBackgroundModes 中包含“location”。

  • 在 UIRequiredDeviceCapabilities 中包含“gps”和“location-services”

  • 如下启动位置管理器:

    let locationManager = CLLocationManager()
    locationManager.desiredAccuracy =
        kCLLocationAccuracyHundredMeters
    locationManager.distanceFilter = 250.0
    locationManager.allowsBackgroundLocationUpdates = true
    locationManager.startUpdatingLocation()
    
  • 我也证实了 locationManager.pausesLocationUpdatesAutomatically 为 false。

当应用程序不在前台时,我没有位置更新。我唯一一次获得位置更新是在我将应用程序调到前台时,即便如此,也不是一直如此。

知道出了什么问题吗?还是我的期望不正确?

最佳答案

您如何将应用程序发送到后台?如果您滑动以终止,那么您的应用程序将不会自动重启以接收位置事件。我在你的代码中没有看到它,你调用了 requestAlwaysAuthorization 了吗?您可能还想实现 LocationManager:didFailWithError 只是为了看看是否能给您任何想法。

关于ios 9 应用程序不在后台报告位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37289535/

相关文章:

iOS SDK : Feed Dialog without authorize gets send to facebook home page

ios - Rxswift 结合多个可观察的奇怪行为

ios - 超时获取位置

iphone - 边界检测纸张opencv

ios - 同时使用 AVAudioRecorder 和 AvAudioPlayer

ios - 通过 OpenTok 的 iOS SDK 发送 OpenTokSignal

swift 从终端抛出 python 错误

ios - AVSpeechSynthesizer 使用一次后无法正常工作

ios - 如何根据条件语句转至 View Controller ?

ios - 我想在 Swift 中找到朝拜方向(简单的方向指南针)