本文介绍了你如何以编程方式获取iPhone的序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道使用我的应用程序的iPhone的序列号。我在下面写了代码。
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?
推荐答案您应该从 CFSTR(kIOPlatformUUIDKey)更改 IORegistryEntryCreateCFProperty 的参数2 到 CFSTR(kIOPlatformSerialNumberKey)。然后你会得到正确的序列号(长度为11个字符)。
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).
更多推荐
你如何以编程方式获取iPhone的序列号?
发布评论