How do you programmatically get the serial number of an iPhone?

iphone, objective-c

Solution

You should change the argument 2 of `IORegistryEntryCreateCFProperty` from `CFSTR (kIOPlatformUUIDKey)` to `CFSTR (kIOPlatformSerialNumberKey)`. Then you will get the correct serial number(with length of 11 characters).

Problem

I want to know the serial number of my iPhone using my application. I have writen code below. ``` - (NSString*)getSerialNumber { CFTypeRef serialNumberAsCFString; io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); if (platformExpert) { serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); } IOObjectRelease(platformExpert); NSString *serial = [[NSString alloc] initWithFormat:@"%@",serialNumberAsCFString]; NSLog(@"serail no==>%@",serialNumberAsCFString); NSLog(@"serail no==>%@",serial); } ``` Why am I still getting wrong serial number?

Original source