I have a Live App released on ios 7 and using background services.
I am recompiling the app under ios 9 and have now found that the app does not receive any location update while it enters the background.
I have made the following change:
- I've added the following key to my info.plist file with an accompanying String value: NSLocationWhenInUseUsageDescription
Still when the app goes in background, it stops receiving location updates.
Is there any other setting or method I should include which will allow the app to receive location update in the background as does the live app?
Hope this helps you:
Make sure You have selected location updates in capabilities
.
Also check backgroundMode in app delegate in app
- (void)applicationDidEnterBackground:(UIApplication *)application
{
self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"ending background task");
[[UIApplication sharedApplication] endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
}];
//You can use timer selected time intervals
}
This new property is explained in the WWDC session "What's New in Core Location".
The default value is NO if you link against iOS 9.
If your app uses location in the background (without showing the blue status bar) you have to set allowsBackgroundLocationUpdates to YES in addition to setting the background mode capability in Info.plist. Otherwise location updates are only delivered in foreground. The advantage is that you can now have location managers with background location updates and other location managers with only foreground location updates in the same app. You can also reset the value to NO to change the behavior.
The documentation is pretty clear about it:
By default, this is NO for applications linked against iOS 9.0 or later, regardless of minimum deployment target.
With UIBackgroundModes set to include "location" in Info.plist, you must also set this property to YES at runtime whenever calling -startUpdatingLocation with the intent to continue in the background.
Setting this property to YES when UIBackgroundModes does not include "location" is a fatal error.
Resetting this property to NO is equivalent to omitting "location" from the UIBackgroundModes value. Access to location is still permitted whenever the application is running (ie not suspended), and has sufficient authorization (ie it has WhenInUse authorization and is in use, or it has Always authorization). However, the app will still be subject to the usual task suspension rules.
See -requestWhenInUseAuthorization and -requestAlwaysAuthorization for more details on possible authorization values.
Reference for this answer - allowsBackgroundLocationUpdates in CLLocationManager in iOS9
Google search - https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=location+update+in+ios+9+in+background
Try http://mobileoop.com/background-location-update-programming-for-ios-7.
It works on iOS 9 as well.