How to know when iOS device is plugged in?

前端 未结 3 1960
闹比i
闹比i 2020-12-29 16:14

Is there a way to know when my device (iPhone) is plugged in to source power, like a computer or car audio systems with a USB port? I use localization services in my app and

3条回答
  •  梦谈多话
    2020-12-29 16:28

    You can enable battery monitoring thru the UIDevice class and check the battery state to see if it is being charged:

    typedef enum {
        UIDeviceBatteryStateUnknown,
        UIDeviceBatteryStateUnplugged,
        UIDeviceBatteryStateCharging,
        UIDeviceBatteryStateFull,
    } UIDeviceBatteryState;
    

    You'll want to check for Charging or Full before enabling best GPS accuracy.

提交回复
热议问题