4

我很想知道 iOS 中是否有任何可能性,通过它我们可以知道设备是通过 USB 电缆还是 Wallport 连接的。换句话说,我希望我的应用程序显示设备是通过 USB 电缆还是壁式端口充电。

4

2 回答 2

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;
于 2013-04-08T05:56:43.017 回答
0

这是不可能的——而且可能没有充分的理由依赖它。

想想许多不同类型的计算机,打开和关闭,安装和未安装软件,用户登录或注销,以及数百种不同的充电器型号、USB 集线器,甚至屏幕都带有 USB。

于 2013-09-24T07:34:58.193 回答