Search
Recommended for You

Retrieving Device Information


As the open iPhone toolchain reveals, Apple has supplied a limited device-specific information class. You can retrieve far more information from your iPhone through its IO Registry. As on the Macintosh, the IO Registry provides a great deal of hardware specific information, which can be queried and used by your programs.

The IO Registry depends on the IO Kit framework, a private framework that is available only to jailbreak applications. The following function allows you to search through the registry and return matching data as an array of string values.

id getValue(NSString *iosearch)
{
    mach_port_t          masterPort;
    CFTypeID             propID=NULL;
    unsigned int         bufSize;

    kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
    if (kr != noErr) return NULL;

    io_registry_entry_t entry = IORegistryGetRootEntry(masterPort);
    if (entry == MACH_PORT_NULL) return NULL;

    CFTypeRef prop = IORegistryEntrySearchCFProperty(entry,
       kIODeviceTreePlane, iosearch, nil, 
       kIORegistryIterateRecursively);
    if (prop == nil) return NULL;
      else propID = CFGetTypeID(prop);
    if (!propID == CFDataGetTypeID()) {
       mach_port_deallocate(mach_task_self(), masterPort);
       return NULL;}

    CFDataRef propData = (CFDataRef)prop;
    if (!propData) return NULL;

    bufSize = CFDataGetLength(propData);
    if (!bufSize) return NULL;

    id p1 = [[NSString alloc] 
       initWithBytes:CFDataGetBytePtr(propData) length:bufSize encoding:1];
    mach_port_deallocate(mach_task_self(), masterPort);
    return [p1 componentsSeparatedByString:@"\0"];
}

Sending the string @"compatible" to this function returns an array of the platform name (iPhone or iPod), the platform code (such as M68AP or N45AP), and the platform processor. Other arguments you might pass include @"serial-number", @"device-imei", @"model-number", and @"backlight-level".

Download a copy of the IO registry tools from Cydia and use ioreg to explore the full extent of values your iPhone can report. You can incorporate the functionality seen here into your applications to easily recover hardware settings for those values.

AddThis Social Bookmark Button
Comments (1)

1 Comments

dksite said:

Hi Erica,

I love your posts here and at TUAW. I have a quick question for you though...I noticed that your flashlight app "Light" has been removed from the AppStore. That was my favorite flashlight app because it turned up the brightness of the screen while it was on...I was just wondering if Apple has given you any explanation of why the app had been removed (or if you removed it yourself :p). Again, love all your posts and apps, just wish I could have my "Light" back.

Thanks.

Leave a comment