简体   繁体   English

ios 9 app不在后台报告位置

[英]ios 9 app not reporting location in background

I am writing (in Swift) an iOS 9 app that needs location updates including in background mode. 我正在编写(在Swift中)一个需要位置更新的iOS 9应用程序,包括后台模式。 The problem is that I only get location updates in foreground. 问题是我只在前台获得位置更新。 I think I have done everything correctly: 我想我已经做好了一切:

In info.plist: 在info.plist中:

  • Specified a value for NSLocationAlwaysUsageDescription. 为NSLocationAlwaysUsageDescription指定了值。

  • Specified a value for NSLocationUsageDescription. 为NSLocationUsageDescription指定了值。

  • Specified a value for NSLocationWhenInUseUsageDescription. 为NSLocationWhenInUseUsageDescription指定了值。

  • Included "location" in UIBackgroundModes. 包含在UIBackgroundModes中的“位置”。

  • Included "gps" and "location-services" in UIRequiredDeviceCapabilities 在UIRequiredDeviceCapabilities中包含“gps”和“location-services”

  • Started the location manager as follows: 启动了位置管理器,如下所示:

     let locationManager = CLLocationManager() locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters locationManager.distanceFilter = 250.0 locationManager.allowsBackgroundLocationUpdates = true locationManager.startUpdatingLocation() 
  • I have also verified that locationManager.pausesLocationUpdatesAutomatically is false. 我还验证了locationManager.pausesLocationUpdatesAutomatically是false。

I get no location updates while the app is not in the foreground. 当应用程序不在前台时,我没有获得位置更新。 The only time I do get location updates is if I bring the app to foreground, and even then, not all the time. 我唯一一次获得位置更新是因为我将应用程序带到前台,即便如此,也不是所有时间。

Any idea what's going wrong? 知道出了什么问题吗? Or my expectations incorrect? 或者我的期望不正确?

How are you sending the app to the background? 你是如何将应用程序发送到后台的? If you swipe to kill then your app won't automatically restart to receive the location events. 如果您滑动以杀死,那么您的应用将不会自动重新启动以接收位置事件。 I don't see it in your code, did you call requestAlwaysAuthorization? 我在你的代码中没有看到它,你是否调用了requestAlwaysAuthorization? You might also want to implement LocationManager:didFailWithError just to see if that gives you any ideas. 您可能还想实现LocationManager:didFailWithError,以查看是否能为您提供任何想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM