如何知道 iOS 设备何时插入? [英] How to know when iOS device is plugged in?

查看:15
本文介绍了如何知道 iOS 设备何时插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道我的设备 (iPhone) 何时插入电源,例如带有 USB 端口的计算机或汽车音响系统?我在我的应用程序中使用本地化服务,我想在插入设备时自动更改为 kCLLocationAccuracyBestForNavigation.谢谢...

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...

推荐答案

您可以通过 UIDevice 类 并检查电池状态是否正在充电:

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;

在启用最佳 GPS 精度之前,您需要检查正在充电或已充满.

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

这篇关于如何知道 iOS 设备何时插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆