You want to put the
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
when your app activates. (appDidBecomeActive)
(maybe turn it off when the app deactivates)
But before you enable the monitoring, you have to subscribe to the
UIDeviceBatteryStateDidChangeNotification
from the UIDevice singleton.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryStateDidChange:)
name:UIDeviceBatteryStateDidChangeNotification object:nil];
@selector points to the method that will handle whatever you want to do when the state changes.
Source:
http://stackoverflow.com/questions/14028103/xcode-alert-if-iphone-not-charging