你如何以编程方式获取iPhone的序列号?

编程入门 行业动态 更新时间:2024-10-28 06:31:51
本文介绍了你如何以编程方式获取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的序列号?

本文发布于:2023-11-27 20:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639484.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列号   方式   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!