views:

543

answers:

3

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.

A: 

Try this:

[[UIDevice device] uniqueIdentifier]

for each of your connected devices.

ennuikiller
Ok, but how can I get that list of connected devices? Is there a way to obtain it from a mac application?
luvieere
A: 

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.

Jasarien
I would second the request for more data about what is trying to be achieved here.
Kendall Helmstetter Gelner
I'm trying to obtain that data programatically, just as it is possible with the Windows COM iTunes API. Based on the obtained UUID, I should generate another key for per-device authentication and registration. Anyway, I need to discriminate between IPhone devices connected to my mac machine, just as the iTunes API allows me to do in Windows.
luvieere
A: 

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.

luvieere