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

发布于 2024-12-15 00:16:35 字数 467 浏览 1 评论 0原文

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

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

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

总体思路是确定用户何时在使用计算机。

注意:为了做出此决定,我需要识别设备。对于 iOS,使用设备 UUID(类似于 APNS 中使用的 UUID)。在 Android 中,硬件 ID 和软件 ID 是组合在一起的。所以如果从计算机的角度来解决,我需要能够获取这些字符串。否则,我需要能够将它们传递到计算机。

奖励:如果 Wi-Fi 同步也能被视为“已连接”,那就太棒了。

Is there a way to determine if a smart phone or tablet (iOS or Android), is plugged into a computer?

Either the phone/tablet perspective (i.e. isConnectedToComputer) or the computer perspective (i.e. connectedDevices) would be fine.

If it's from the computer perspective, it would specifically have to be via a Mac OS X app.
If it's from the phone/tablet perspective, it would need to be differentiated from simply charging.

The general idea is to determine when a user is at their computer.

Note: In order to make this determination, I need to identify the device. For iOS, the device UUID (similar to that used in APNS) is used. In Android, a combination hardware and software IDs are combined. So if the solution in from the computer perspective, I need to be able to obtain these strings. Otherwise, I need to be able to pass them to the computer.

Bonus: It would be fantastic if Wi-Fi syncing could also be taken into account as "connected".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爺獨霸怡葒院 2024-12-22 00:16:35

简单的解决方案

考虑通过NSTask使用system_profiler SPUSBDataType
连接我的 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 确定感兴趣的设备是否已连接。

Simple Solution

Consider using system_profiler SPUSBDataType through NSTask.
When my iPhone is connected the following is included in the result:

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

Use system_profiler SPUSBDataType -xml to output the result in XML format:

<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>

Simply parse the XML to determine wether the device of interest is connected or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文