3

My project is using a CLLocationManager object, receiving updates via: locationManager:didUpdateToLocations:

I want these updates even though my app is in the background. So in info.plist i have set the, "Required background modes" list to App registers for location updates.

But my testing shows that it does not receive the updates in background state.

However, i'm not sure i'm having the correct perception of background state/ suspended state. This is how i think it works:

After the home button is pressed, the app enters background mode for 5 seconds, 
and then enter suspended state.

I guess this is why it's not working. But if setting the info.plist to ""app registers for location updates" does not keep the app from reaching suspended state, then how do i achieve it?

What is the difference (if any) in pressing the Home button and pressing the lock button? State-wise i mean.

I have read the relevant parts of this guide: http://www.raywenderlich.com/29948/backgrounding-for-ios

Im still new to IOS, so i might have overlooked something.

János
  • 32,867
  • 38
  • 193
  • 353
Anders
  • 719
  • 8
  • 22

1 Answers1

2

First, have you studied "Getting Location Events in the Background" in the Location and Maps Programming Guide?

Have you checked backgroundRefreshStatus? Is this app allowed to run in the background according to it?

What is the value of pausesLocationUpdatesAutomatically?

What accuracy are you requesting? Are you moving sufficiently to generate changes over that accuracy?

Did you call startUpdatingLocation?

Is this iOS 6 or 7? If iOS 7, make sure to watch Session 204: "What’s New with Multitasking?" There have been several changes and iOS is now more aggressive about shutting down apps than it was previously.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • I have just read it, thanks. Im not familiar with backgroundRefreshStatus. pausesLocationsUpdatesAutomatically is still default value YES. Im using best accuracy possible, and im moving at walking speed. startUpdatingLocations is called at the time the home button is entered. This is for iOS 6 to start with. I will go watch that video. When using my app, im walking a route, putting locations into an array every 30-50 meters. Later i want to know when i get close to either of these locations(say 10 m), this is where i need the app to update locations, even in background. – Anders Sep 20 '13 at 21:52
  • 1
    Have you compared your app to the Regions sample, which does similar things to what you describe? https://developer.apple.com/library/ios/samplecode/Regions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010726. If `pausesLocationUpdatesAutomatically` is `YES`, then perhaps the configuration you're using is causing a pause (moving at walking speed is likely to cause pauses). – Rob Napier Sep 21 '13 at 14:42