Created
April 9, 2013 19:20
-
-
Save samdmarshall/5348565 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| + (NSArray *)devicesSupportingIPhoneOS { | |
| NSMutableArray *devices = [NSMutableArray new]; | |
| io_iterator_t iterator; | |
| mach_port_t masterPort; | |
| kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &masterPort); | |
| if (kr == kIOReturnSuccess && masterPort) { | |
| CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBDeviceClassName); | |
| IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iterator); | |
| io_service_t usbDevice; | |
| while (usbDevice = IOIteratorNext(iterator)) { | |
| CFTypeRef supportsIPhoneOS = IORegistryEntrySearchCFProperty(usbDevice, kIOServicePlane, CFSTR("SupportsIPhoneOS"), kCFAllocatorDefault, kIORegistryIterateRecursively); | |
| if (supportsIPhoneOS) { | |
| CFTypeRef data = IORegistryEntrySearchCFProperty(usbDevice, kIOServicePlane, CFSTR("USB Serial Number"), kCFAllocatorDefault, kIORegistryIterateRecursively); | |
| [devices addObject:(NSString *)data]; | |
| } | |
| IOObjectRelease(usbDevice); | |
| } | |
| } else { | |
| NSLog (@"Error: Couldn't create a master I/O Kit port(%08x)", kr); | |
| } | |
| mach_port_deallocate(mach_task_self(), masterPort); | |
| return devices; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment