Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS电池警报检测_Ios_Alert_Detection_Battery - Fatal编程技术网

iOS电池警报检测

iOS电池警报检测,ios,alert,detection,battery,Ios,Alert,Detection,Battery,我想准确地检测iPhone上何时出现电池电量不足警报。它们似乎达到了电池电量的20%和10%左右 我无法使用ApplicationWillResignActive/DiEnterBackground,因为我需要能够将这些电池电量不足警报与其他可能导致调用ApplicationWillResignActive/DiEnterBackground的事件区分开来。这是该计划的一项要求 我不能使用UIDeviceBatteryLevel-DidChangeNotification,因为即使这些应该在每5

我想准确地检测iPhone上何时出现电池电量不足警报。它们似乎达到了电池电量的20%和10%左右

我无法使用ApplicationWillResignActive/DiEnterBackground,因为我需要能够将这些电池电量不足警报与其他可能导致调用ApplicationWillResignActive/DiEnterBackground的事件区分开来。这是该计划的一项要求

我不能使用UIDeviceBatteryLevel-DidChangeNotification,因为即使这些应该在每5%的更改中发生。。。在实践中,它们似乎有时比当时的电池读数低几个百分点,因此在电池电量低警报出现时不会发生。看这里

是否有任何方法可以准确地检测这些电池电量不足警报,并将其与其他应用程序状态更改分开处理


谢谢大家

您可以使用UIDevice的电池电量属性。例如,如果电池电量低于5%,则显示警报。例如,您可以在应用程序代理中定期共享电池电量

 UIDevice *myDevice = [UIDevice currentDevice]; 
 [myDevice setBatteryMonitoringEnabled:YES]; 
 float batteryLevel = [myDevice batteryLevel];
文件中的说明和说明:

 batteryLevel
 The battery charge level for the device.

 @property (nonatomic, readonly) float batteryLevel  

 Discussion
 Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). Before accessing this property, ensure that battery monitoring is enabled.

 If battery monitoring is not enabled, battery state is UIDeviceBatteryStateUnknown and the value of this property is –1.0.

 Availability
 Available in iOS 3.0 and later.
 See Also
    @property batteryState
    @property batteryMonitoringEnabled
 Declared In
 UIDevice.h

谢谢,这似乎有点贵,但我们会试试的。还有其他建议吗?请使用NSNotification将电池电量控制在30%以内。然后打开轮询以最大限度地提高效率。