iPhone4 how to find out if the power cable is plugged in?

前端 未结 3 1462
眼角桃花
眼角桃花 2021-02-10 14:36

I would like to know if my app is running with an external power cable attached. Is it possible to find out this state at runtime?

An extra question: would this be able

3条回答
  •  眼角桃花
    2021-02-10 14:40

    I had to include the line,

    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

    or else batteryState only returns UIDeviceBatteryStateUnknown. Perhaps this became necessary since this question was initially asked and answered. I found the tip here: Determine accurate iPhone battery level.

提交回复
热议问题