You are better off using:
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
[UIApplication sharedApplication].idleTimerDisabled=YES;
}
This is because you have to concern yourself with
two different states - one is that the battery is charging, and the other when it is fully charged.
If you really wanted to be complete about it - you would register to receive battery monitoring notifications, so you could re-enable the idle timer if the user disconnected main power, etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…