从 Mac 上的 Objective-C 查找已连接 Iphone 设备的 UUID

发布于 2024-08-06 04:16:45 字数 79 浏览 6 评论 0原文

我可以从 Mac 上的 Objective-C 找到已连接 Iphone 设备的 UUID 吗?通过 USB 电缆连接的 Iphone 的列表。

Can I find UUID of connected Iphone devices from the objective-c on the mac? Something of a list of connected Iphones trough the usb cable.

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

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

发布评论

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

评论(3

被你宠の有点坏 2024-08-13 04:16:46

尝试一下:

[[UIDevice device] uniqueIdentifier]

对于每个连接的设备。

Try this:

[[UIDevice device] uniqueIdentifier]

for each of your connected devices.

凤舞天涯 2024-08-13 04:16:45

使用 ioreg 命令,并 grep 收到的结果。一个极简的实现:

- (NSString*)getConnectedIphoneUIID
{
NSTask *ioRegTask = [[NSTask alloc] init];
[ioRegTask setLaunchPath:@"/usr/sbin/ioreg"];
[ioRegTask setArguments:[NSArray arrayWithObjects:@"-Src",@"IOUSBDevice",nil]];

NSTask *grepTask = [[NSTask alloc] init];
[grepTask setLaunchPath:@"/usr/bin/grep"];
[grepTask setArguments:[NSArray arrayWithObjects:@"-i", @"usb serial number", nil]];

NSPipe *ioregToGrepPipe = [[NSPipe alloc] init];
[ioRegTask setStandardOutput:ioregToGrepPipe];
[grepTask setStandardInput:ioregToGrepPipe];

NSPipe *outputPipe = [[NSPipe alloc] init];
[grepTask setStandardOutput:outputPipe];
NSFileHandle *outputFileHandle = [[outputPipe fileHandleForReading] retain];

[ioRegTask launch];
[grepTask launch];


NSData *outputData = [[outputFileHandle readDataToEndOfFile] retain];

[ioRegTask release];
[grepTask release];
[outputData release];

NSString *nvcap = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];

     return nvcap;
  }

我可以合并更多检查并进一步解析结果,以确保它确实是一部 iPhone,以防万一其中列出了更多设置了“USB 序列号”属性的设备。检查“SupportsIPhoneOS”属性将进一步确认设备的身份。这样,我实际上可以构建已连接的 iPhone/iPod 设备的列表,并从“usb 序列号”属性中获取它们的 UUID。

Use the ioreg command, and grep the received results. A minimalist implementation:

- (NSString*)getConnectedIphoneUIID
{
NSTask *ioRegTask = [[NSTask alloc] init];
[ioRegTask setLaunchPath:@"/usr/sbin/ioreg"];
[ioRegTask setArguments:[NSArray arrayWithObjects:@"-Src",@"IOUSBDevice",nil]];

NSTask *grepTask = [[NSTask alloc] init];
[grepTask setLaunchPath:@"/usr/bin/grep"];
[grepTask setArguments:[NSArray arrayWithObjects:@"-i", @"usb serial number", nil]];

NSPipe *ioregToGrepPipe = [[NSPipe alloc] init];
[ioRegTask setStandardOutput:ioregToGrepPipe];
[grepTask setStandardInput:ioregToGrepPipe];

NSPipe *outputPipe = [[NSPipe alloc] init];
[grepTask setStandardOutput:outputPipe];
NSFileHandle *outputFileHandle = [[outputPipe fileHandleForReading] retain];

[ioRegTask launch];
[grepTask launch];


NSData *outputData = [[outputFileHandle readDataToEndOfFile] retain];

[ioRegTask release];
[grepTask release];
[outputData release];

NSString *nvcap = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];

     return nvcap;
  }

I could incorporate more checks and further parse the results, to make sure it's really an iPhone, just in case there are more devices listed in there that have the "usb serial number" property set. Checking the "SupportsIPhoneOS" property would further confirm the device's identity. This way, I could actually build a list of connected iPhone/iPod devices, and get their UUID's from the "usb serial number" property.

三寸金莲 2024-08-13 04:16:45

苹果公司对 iPhone 保持着高度锁定。我认为如果不通过 USB 编写一些低级代码,您会发现从 iPhone 查询任何内容都不容易。

您需要这样做有什么具体原因吗?您不能只查看 Xcode 中的 Organizer 窗口并查看那里连接了哪些设备吗? Organizer 显示 UUID 和有关连接设备的更多信息,包括崩溃时间、iPhone 控制台、屏幕截图和配置。

Apple keeps the iPhone pretty locked down. I don't think you'd find it easy to query anything from the iPhone without some low level code over USB.

IS there a specific reason you need to do this? Can you not just look in the Organizer window in Xcode and see what devices are connected there? The Organizer shows the UUIDs and more information about connected devices, including crash longs, the iPhone's console, screenshots and provisioning.

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