Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect low battery warning ios [duplicate]

I'm making a turnbased game. To prevent users from cheat, the turn will automatically get passed to the opponent if the user close the app in the middle of a turn. This because so the user can't close the app, restart it, and beging the turn from the beginning.

There are two cases that should penalize the player however. If a phone call gets in, or the low battery warning appears. I can detect the phone call coming in and respond, but I don't know what to do with the battery?

Any suggestions would be awesome

like image 894
BlackMouse Avatar asked Dec 11 '22 17:12

BlackMouse


1 Answers

Battery monitoring is enabled by setting to YES a property of the UIDevice singleton:

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

iPhone OS provides two type of battery monitoring events, one for when the state changes (e.g., charging, unplugged, full charged) and one that updates when the battery’s charge level changes. As was the case 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 refer this link.

like image 122
iPatel Avatar answered Jan 19 '23 08:01

iPatel