How to get IMEI on iPhone 5

落花浮王杯 提交于 2019-11-27 13:50:18

There are several ways to get IMEI on newer devices

1) Private ManagedConfiguration.framework

CFStringRef MCCTIMEI()

2) CoreTelephony.framework

struct CTResult
{
    int flag;
    int a;
};
extern CFStringRef kCTMobileEquipmentInfoIMEI;

void *connection = _CTServerConnectionCreate(kCFAllocatorDefault, NULL, NULL);

NSDictionary *info = nil;
struct CTResult result;
_CTServerConnectionCopyMobileEquipmentInfo(&result, connection, &info);
[info autorelease];    
CFRelease(connection);

NSString* IMEI = (NSString*)info[(NSString*)kCTMobileEquipmentInfoIMEI];

3) liblockdown.dylib

extern CFStringRef kLockdownIMEIKey;

void* connection = lockdown_connect();
NSString* IMEI = [(NSString*)lockdown_copy_value(connection, NULL, kLockdownIMEIKey) autorelease];
lockdown_disconnect(connection);

I had some problems with MCCTIMEI - returned empty IMEI after device start-up. Now I'm using CoreTelephony solution, never had a problem with it.

UPDATE

On iOS 7 these APIs are protected by com.apple.coretelephony.Identity.get entitlement. To access IMEI (IMSI, phone number and other info) you need to sign your with that entitlement with boolean value set to true.

manujmv

It have some difficult get the IMEI number programatically. However, if you're looking for a way to identify a particular phone, you can use the UDID (Unique Device Identifier) to do so.

NSString *UDID = [[UIDevice currentDevice] uniqueIdentifier];

and also try this for IMEI

NSString *imei = [[NetworkController sharedInstance] IMEI];

******Update Oct 2014******

NSUUID *UUID = [[UIDevice currentDevice] identifierForVendor];
NSString *stringUUID = [UUID UUIDString];

The UUID is an essentially unique identifier for your phone's hardware. It's not guaranteed to be unique due to no collaboration between manufacturers but, given the number of combinations, it is a reasonably reliable identifier of hardware for a broad range of applications.

You can use it:


Download following two files from GitHub

OpenUDID.h
OpenUDID.m

Add these files to your project.

And use it as

#import "OpenUDID.h"

NSString* openUDID = [OpenUDID value];

It is tested in iPhone 4 and iPhone 5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!