智能手机和平板电脑 - 插入计算机



有没有办法确定智能手机或平板电脑(iOS或Android)是否插入了电脑?

手机/平板电脑视角(即isConnectedToComputer)或电脑视角(即connectedDevices)都可以。

如果是从计算机的角度来看,它将特别必须通过Mac OS X应用程序。如果从手机/平板电脑的角度来看,它需要与简单的charging区分开来。

一般的想法是确定用户何时在他们的计算机上。

注意:为了做出这个判断,我需要识别设备。对于iOS,使用设备UUID(与APNS类似)。在Android中,硬件和软件id是结合在一起的。如果从计算机的角度来解,我需要能够得到这些字符串。否则,我需要能够将它们传递给计算机。

奖励:如果Wi-Fi同步也可以考虑为"连接",那将是非常棒的。

简单的解决方案

考虑使用system_profiler SPUSBDataTypeNSTask
当我的iPhone连接时,结果中包含以下内容:

iPhone:
 Product ID: 0x1292
 Vendor ID: 0x05ac  (Apple Inc.)
 Version: 0.01
 Serial Number: 
 Speed: Up to 480 Mb/sec
 Manufacturer: Apple Inc.
 Location ID: 0xfa140000 / 6
 Current Available (mA): 500
 Current Required (mA): 500
 Extra Operating Current (mA): 500

使用system_profiler SPUSBDataType -xmlXML格式输出结果:

<dict>
    <key>_name</key>
    <string>iPhone</string>
    <key>a_product_id</key>
    <string>0x1292</string>
    <key>b_vendor_id</key>
    <string>apple_vendor_id</string>
    <key>c_bcd_device</key>
    <string> 0.01</string>
    <key>d_serial_num</key>
    <string></string>
    <key>e_device_speed</key>
    <string>high_speed</string>
    <key>f_manufacturer</key>
    <string>Apple Inc.</string>
    <key>g_location_id</key>
    <string>0xfa140000 / 6</string>
    <key>h_bus_power</key>
    <string>500</string>
    <key>j_bus_power_used</key>
    <string>500</string>
    <key>k_extra_current_used</key>
    <string>500</string>
</dict>

只需解析XML以确定感兴趣的设备是否已连接。

最新更新