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

查看:104
本文介绍了如何知道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 class 并检查电池状态以查看是否收费:

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天全站免登陆