Search code examples
iphoneioscocoa-touchcore-datauidevice

iOS: Monitoring Battery Level uses more battery? Should auto-save?


I have a GPS app that already uses a fair amount of battery. Because of the nature of the app, I don't want the user to loose all of their data if their battery dies without them knowing it. So, I figured I would monitor the battery and then save and stop the GPS data if the battery is very low. I would use:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(batteryStateDidChange:)
                                             name:UIDeviceBatteryStateDidChangeNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(batteryLevelDidChange:)
                                             name:UIDeviceBatteryLevelDidChangeNotification
                                           object:nil];

So, a few questions:

  • Would monitoring the battery cause even MORE battery drain?
  • Is it a good idea to auto-save (core-data) for the user right before the battery dies?

Solution

  • The device already has to monitor battery notifications in order to display the battery level when the time / carrier / signal strength is visible... I wouldn't expect registering for the notifications would add any additional stress to anything (power consumption). Maybe a few extra cpu cycles from your app for handling the notification. :-)

    Auto saving might be a smart idea.

    But another idea might be to cease GPS / CoreLocation services for your app once battery gets underneath a certain level (or offer that as a user-settable option).