如何知道 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过 UIDevice 类 启用电池监控并检查查看电池状态以查看是否正在充电:
在启用最佳 GPS 精度之前,您需要检查是否正在充电或已充满。
You can enable battery monitoring thru the UIDevice class and check the battery state to see if it is being charged:
You'll want to check for Charging or Full before enabling best GPS accuracy.
您可以注册以便在配件连接或断开连接时收到通知。
示例:
一旦收到此通知,您可以使用 for 循环来遍历每个附件,例如:
在某些时候(也许是释放)您将希望取消注册这些通知。你可以这样做:
You can register to be notified when an accessory connects or disconnects.
Example:
Once you receive this notification you can use a for loop to go through each accessory like:
At some point (dealloc perhaps) you will want to unregister for these notifications. You can do this like:
检查电池状态:
订阅有关电池状态变化的通知,例如通过调用您自己的操作方法
batteryStateChanged
:请记住在对象被释放时取消订阅:
To check the state of the battery:
To subscribe to notifications about changes in the battery state, for instance by getting a call to your own action method
batteryStateChanged
:Remember to unsubscribe when your object is dealloced: