Low battery alert detection

I'm making a reversal game. To prevent users from cheating, the queue will be automatically transferred to the enemy if the user closes the application in the middle of the turn. This is because the user cannot close the application, restart it and ask for a rotation from the beginning.

There are two cases that should punish the player. If a phone call comes in or a low battery warning appears. I can detect an incoming call and answer, but I don't know what to do with the battery?

Any suggestions would be awesome

+3


source to share


1 answer


Battery monitoring is enabled by setting the UIDevice

singleton property to YES :

UIDevice *device = [UIDevice currentDevice];
device.batteryMonitoringEnabled = YES;

      

iPhone OS

Provides two types of battery monitoring events, one for when the state changes (eg, charging, disconnecting, fully charged) and one that is updated when the battery level changes. As with proximity monitoring, you register callbacks to receive notifications:



[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryLevelDidChangeNotification" object:device];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryStateDidChangeNotification" object:device];

      

Also link to this link.

+12


source







All Articles