一种简便获取iPhone IMEI 的方法

自从NetworkController失效后, 一般都是采用 erica的方法

https://github.com/erica/uidevice-extension/blob/master/UIDevice-IOKitExtensions.m

UIDevice继承了IOKit_Extensions, 通过读取IO端口的方法, 取 device-imei

这种方法比较繁琐, 并且 尽管IOKit是一个公开的framework, 但是非常底层地同硬件和内核服务打交道, 苹果不鼓励任何人使用它, 并且这样的程序进入AppStore审核时会被拒绝的

所以,还不如直接使用CoreTelephony库,它也是一个公开的framework,但很多API没有出现在文档中

iPhone私有API跟电话相关的CoreTelephony 里面提到了很多API, 其中有些可能跟电话录音有关系.

其中 _CTServerConnectionCopyMobileIdentity 就是用来获取IMEI的

#import

struct CTServerConnection
{
int a;
int b;
CFMachPortRef myport;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
};

struct CTResult
{
int flag;
int a;
};

struct CTServerConnection * _CTServerConnectionCreate(CFAllocatorRef, void *, int *);

void _CTServerConnectionCopyMobileIdentity(struct CTResult *, struct CTServerConnection *, NSString **);
保存为 CoreTelephony.h

#import "CoreTelephony.h"

struct CTServerConnection *sc=NULL;
struct CTResult result;

void callback() { }

int main()
{
sc = _CTServerConnectionCreate(kCFAllocatorDefault, callback, NULL);

NSString *imei;
_CTServerConnectionCopyMobileIdentity(&result, sc, &imei);

NSLog (@"zhiwei's IMEI is %@", imei);

return 0;
}

保存为zhiwei.m

用下面的命令编译
gcc -arch armv7
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
-framework Foundation -framework CoreTelephony
zhiwei.m -o imei

http://www.iloss.me/2011/10/11/%E4%B8%80%E7%A7%8D%E7%AE%80%E4%BE%BF%E8%8E%B7%E5%8F%96iphone-imei-%E7%9A%84%E6%96%B9%E6%B3%95/#comment-291

原文地址:https://www.cnblogs.com/qq378829867/p/2780912.html