智能手机和平板电脑 - 插入计算机
有没有办法确定智能手机或平板电脑(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的解决方案
考虑通过
NSTask
使用system_profiler SPUSBDataType
。连接我的 iPhone 后,结果中包含以下内容:
使用
system_profiler SPUSBDataType -xml
以XML
格式输出结果:只需解析
XML
确定感兴趣的设备是否已连接。Simple Solution
Consider using
system_profiler SPUSBDataType
throughNSTask
.When my iPhone is connected the following is included in the result:
Use
system_profiler SPUSBDataType -xml
to output the result inXML
format:Simply parse the
XML
to determine wether the device of interest is connected or not.