简体   繁体   中英

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. The problem is that I only get location updates in foreground. I think I have done everything correctly:

In info.plist:

  • Specified a value for NSLocationAlwaysUsageDescription.

  • Specified a value for NSLocationUsageDescription.

  • Specified a value for NSLocationWhenInUseUsageDescription.

  • Included "location" in UIBackgroundModes.

  • Included "gps" and "location-services" in UIRequiredDeviceCapabilities

  • 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.

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? You might also want to implement LocationManager:didFailWithError just to see if that gives you any ideas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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