Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: background GPS stopping by itself?

Tags:

ios

I have an application that calls [locationManager startUpdatingLocation] and never calls [locationManager stopUpdatingLocation] as the GPS is meant to run in the background.

I have set my info.plist file to allow the app to register for background location updates. But I've noticed once in a while (when the app is in the background), that the little arrow at the top right of the screen indicating that the GPS is on, turns off by itself.

Is there any reason this should happen?

I call [locationManager startUpdatingLocation] only once, in the applicationDidBecomeActive method. Should I also be calling it in the applicationDidEnterBackground method??

like image 797
PaulG Avatar asked May 31 '13 20:05

PaulG


People also ask

Why does my GPS keep turning off iPhone?

If the iPhone's screen turns off while using Google Maps, it means the Auto-Lock setting has been configured to turn off the screen after a set period of inactivity to save energy.

Why does my Apple Maps keep stopping?

To conclude, if Apple Maps keeps crashing on iOS, restart the app. If the problem persists, install the latest Apple Maps and iOS updates, and force restart your iPhone. If reinstalling the app doesn't solve the problem, switch to a different GPS and navigation app such as Google Maps or Waze.


2 Answers

UPDATED: You can use the standard updates in the background. According to Apple:

If your app needs location updates delivered whether the app is in the foreground or background, there are multiple options for doing so. The preferred option is to use the significant location change service to wake your app at appropriate times to handle new events. However, if your app needs to use the standard location service, you can declare your app as needing background location services.

An app should request background location services only if the absence of those services would impair its ability to operate. In addition, any app that requests background location services should use those services to provide a tangible benefit to the user. For example, a turn-by-turn navigation app would be a likely candidate for background location services because of its need to track the user’s position and report when it is time to make the next turn.

Take a look at this link: http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4


Apps running in the background are usually meant to use [locationManager startMonitoringSignificantLocationChanges]; instead of the standard [locationManager startUpdatingLocation];.

Apple has some rigid guidelines on this subject. If you have not already you should really read up on it here:

http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW1

Chances are that your location updates are stopping because you are using the standard location update in the background instead of the significant location changes.

like image 38
sangony Avatar answered Sep 25 '22 13:09

sangony


From the apple docs:

Allowing the location manager to pause updates can improve battery life on the target device without sacrificing location data. When this property is set to YES, the location manager pauses updates (and powers down the appropriate hardware) at times when the location data is unlikely to change. For example, if the user stops for food while using a navigation app, the location manager might pause updates for a period of time. You can help the determination of when to pause location updates by assigning a value to the activityType property.

There has been a change in iOS 6 regarding Core Location. You need to disable the AutoPause. Change pausesLocationUpdatesAutomatically to NO. Location updates will be send even when the app goes in the background, like it used to work in < iOS 6.

http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

like image 66
Segev Avatar answered Sep 23 '22 13:09

Segev