Receiving GPS updates in the background

Hi,

I’m doing an app that sends GPS data to a server. It works fine as long as the app is in the foreground, but not when it’s in the background. Here’s what I did so far:

  1. In Info.plist, I set
  
UIApplicationExitsOnSuspend  

to NO. As I understand, this keeps the app from shutting down completely, and puts it in hibernation.

  1. In Info.plist, I added the key
  
UIBackgroundModes  

, add I added

  
location  

to it. If I get things right, it means that my app should receive location update events, even when in background.

However, update() and draw() don’t seem to run when I test this with the app backgrounded. My guess is that I need to add a few event handlers to my app, like locationDidUpdate, and stick my code in there. Is that correct, and how would I do that?

In my setup(), I added:

  
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];   

This prevents the phone from going into sleep mode. I’m using this as a temporary solution, but of course it would be nice to also get GPS events when the app is in the background.

Hi there,

did you find a solution ? i’m also trying to get location updates while in background…

cheers…

Hello,

This project is on hold and I haven’t worked more on it. This is from my notes on the project:

In theory the background mode technique should work, but I think the problem is that the callback that can respond to this is currently not implemented in openFrameworks. Something like ofxiPhoneCoreLocationKitListener is needed, in the same style as ofxiPhoneMapKitListener. Then we could use didUpdateLocations() in testApp - that’s where you would put the code that responds to location updates in the background. (Not in iOS5 and before: it’s didUpdateToLocation:fromLocation).

This is new in iOS 6, seems very useful:

“In iOS 6 and later, you can defer the delivery of location data when your app is in the background. It is recommended that you use this feature in situations where your app could process the data later without any problems. For example, an app that tracks the user’s location on a hiking trail could defer updates until the user hikes a certain distance and then process the points all at once. Deferring updates helps save power by allowing your app to remain asleep for longer periods of time.”

See http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager-Class/CLLocationManager/CLLocationManager.html#//apple-ref/doc/uid/TP40007125.

I hope this helps!