我想知道使用我的应用程序的iPhone的序列号.我在下面写了代码.
- (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); }
为什么我的序列号仍然错误?
你应该改变的参数2 IORegistryEntryCreateCFProperty
,从CFSTR (kIOPlatformUUIDKey)
到CFSTR (kIOPlatformSerialNumberKey)
.然后您将获得正确的序列号(长度为11个字符).