How do I know when the iOS device is plugged in?

advertisements

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 I want to change to kCLLocationAccuracyBestForNavigation automatically when the device is plugged. Thanks...


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.