I wish for my app to act differently when the phone is docked or otherwise connected to the computer. Is this possible?
Turn off Handoff on your devices iPad, iPhone, and iPod touch: Go to Settings > General > AirPlay & Handoff. Mac: Choose Apple menu > System Preferences, click General, then deselect “Allow Handoff between this Mac and your iCloud devices.”
Open the Watch app on your iPhone. Tap the My Watch tab, then tap Dock.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With