2013-04-08 162 views
4

我很想知道在iOS中是否有可能通過USB線或Wallport連接設備。換句話說,我希望我的應用能夠顯示設備是通過USB電纜還是牆上端口進行充電。如何知道iOS設備是通過USB還是Wall Port Charger連接?

+0

「ios api charging」的第一個google結果:http://iosdevelopertips.com/device/display-battery-state-and-level-of-charge.html – 2013-04-08 05:51:35

+0

@EvanTrimboli該文章無關。 OP希望區分收到的費用類型(通過USB或通過牆上充電器)。 – borrrden 2013-04-08 05:53:28

回答

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; 
+0

我已經這樣做了,但我想知道我的設備是通過USB還是AC Wallport連接 – 2013-04-08 06:33:36

0

這是不可能的 - 有可能是沒有好理由取決於它。

想想很多不同類型的電腦,打開和關閉,軟件安裝和沒有,用戶登錄或註銷,以及數以百計的不同類型的充電器,USB集線器,甚至屏幕都帶有USB。

相關問題