开发者

Can i check to see if the iPhone is docked?

I wish for my app to act differently when the phone is docked or otherwise connected to the computer.开发者_JS百科 Is this possible?


I couldn't find anything offhand about whether it's docked, but if you look at the UIDevice class you'll find the batteryState property. If you enable battery monitoring in your app, you can check to see if the property is set to UIDeviceBatteryStateUnplugged, implying the device isn't docked. If it's another value (UIDeviceBatteryStateCharging or UIDeviceBatteryStateFull), the phone is connected to power.

Note this doesn't guarantee there's a computer at the other end; it could just as easily be a power adapter into a wall or other USB-powered device.


You can also monitor accessory connection changes using EAAccessoryManager class method 'registerForLocalNotifications' and adding observer for notifications EAAccessoryDidConnectNotification, EAAccessoryDidDisconnectNotification.for more reference see apple docs EAAccessoryManager

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜