views:

70

answers:

2

I am using the 'location' UIBackgroundMode to receive GPS background updates when the user presses the Home button. As a result, if the app is left in background mode overnight, the battery is consistently dead the next morning. I have told the locationManager to stopUpdatingLocation, but to no effect.

I understand Apple doesn't want developers to use exit - in fact it seems to have little effect on the app other than to take it to the background - but I can't afford to have the battery die if the user doesn't end the app.

Any suggestions?

A: 

Not an iOS4 developer but the typical approach to this problem is to add a listener for the "home button pressed" event and suspend the GPS module.

Peter Hanneman
He wants it to run in the background when the user presses the home button. You don't need a listener for this either, you simply implement the applicationDidEnterBackground and applicationWillResignActive methods in the application delegate.
Flash84x
A: 

Maybe you could register for a local notification that informs the user they should open the app to stop location tracking? It's not very elegant of course, it seems Apple should allow the developer to register for location updates for a specified length of time, maybe you could submit a feature request for that. I think Loopt monitors for 24 hours and then quits, maybe you could research into how they made it stop after 24 hours. I wish I could help more but I haven't messed with the location framework at all.

Flash84x
Thanks Flash, and you're correct that the app is designed to run in the background under specific conditions. Apple goes so far as to discourage using location services in the background - interesting as they also opened the API to permit just that behavior. I'll keep looking ...
Roger