你如何以编程方式获取iPhone的序列号? [英] How do you programmatically get the serial number of an iPhone?

查看:498
本文介绍了你如何以编程方式获取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的序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆