Simulating low battery for iPhones

后端 未结 4 1688
南笙
南笙 2021-01-01 09:27

I am working on a mobile game, which appearantly crashes when the Low Battery alert is displayed. It works fine on low memory, incoming calls and other messages.

Its

4条回答
  •  误落风尘
    2021-01-01 10:05

    In iOS there is way to simulate "Low Battery"

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

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

    iOS 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];
    

提交回复
热议问题