我很想知道在iOS中是否有任何可能性,我们可以通过USB电缆或Wallport来了解设备是否已连接。换句话说,我希望我的应用程序显示设备是通过USB电缆还是Wall端口充电。
答案 0 :(得分:3)
来自UIDevice班级参考
UIDeviceBatteryStateDidChangeNotification
Posted when battery state changes.
For this notification to be sent, you must set the batteryMonitoringEnabled property to YES.
You can obtain the battery state by getting the value of the batteryState property.
收到通知后,必须检查
UIDeviceBatteryState == UIDeviceBatteryStateUnplugged
枚举
UIDeviceBatteryState
The battery power state of the device.
typedef enum {
UIDeviceBatteryStateUnknown,
UIDeviceBatteryStateUnplugged,
UIDeviceBatteryStateCharging,
UIDeviceBatteryStateFull,
} UIDeviceBatteryState;
答案 1 :(得分:0)
这是不可能的 - 并且可能没有充分理由依赖它。
想想许多不同类型的计算机,打开和关闭,安装和不安装软件,用户登录或注销,以及数百种不同的充电器型号,USB集线器,甚至屏幕都带有USB。