简体   繁体   English

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

[英]Find UUID of connected Iphone devices from the objective-c on the mac

Can I find UUID of connected Iphone devices from the objective-c on the mac? 我可以从Mac上的Objective-C中找到已连接的Iphone设备的UUID吗? Something of a list of connected Iphones trough the usb cable. 通过USB电缆连接的Iphone列表。

Use the ioreg command, and grep the received results. 使用ioreg命令,并grep收到的结果。 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. 我可以进行更多检查并进一步解析结果,以确保它确实是iPhone,以防万一其中列出了更多设置了“ usb序列号”属性的设备。 Checking the "SupportsIPhoneOS" property would further confirm the device's identity. 检查“ SupportsIPhoneOS”属性将进一步确认设备的身份。 This way, I could actually build a list of connected iPhone/iPod devices, and get their UUID's from the "usb serial number" property. 这样,我实际上可以建立一个连接的iPhone / iPod设备的列表,并从“ usb序列号”属性中获取其UUID。

Apple keeps the iPhone pretty locked down. 苹果一直保持iPhone锁定状态。 I don't think you'd find it easy to query anything from the iPhone without some low level code over USB. 我认为,如果没有通过USB的低级代码,就很难从iPhone查询任何内容。

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? 您不仅可以在Xcode的Organizer窗口中查看并查看那里连接了哪些设备? The Organizer shows the UUIDs and more information about connected devices, including crash longs, the iPhone's console, screenshots and provisioning. 组织者会显示UUID和有关已连接设备的更多信息,包括崩溃时长,iPhone的控制台,屏幕截图和配置。

Try this: 尝试这个:

[[UIDevice device] uniqueIdentifier]

for each of your connected devices. 每个连接的设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM