【问题标题】:How to know whether iOS device is connected via USB or Wall Port Charger?如何知道 iOS 设备是通过 USB 还是 Wall Port Charger 连接的?
【发布时间】:2013-03-30 02:54:01
【问题描述】:

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

【问题讨论】:

  • “ios api 收费”的第一个谷歌结果:iosdevelopertips.com/device/…
  • @EvanTrimboli 那篇文章不相关。 OP 想要区分接收到的充电类型(通过 USB 或壁式充电器)。
  • @Syed 你找到解决这个问题的方法了吗?

标签: iphone ios ios5 ios6 ios6.1


【解决方案1】:

来自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;

【讨论】:

  • 我已经这样做了,但我想知道我的设备是通过 USB 还是 AC Wallport 连接的
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 2021-08-25
    • 2014-04-25
    • 2017-09-29
    • 2015-03-17
    • 1970-01-01
    • 2011-08-15
    相关资源
    最近更新 更多