How to Get Imei on iPhone 5

How to get IMEI on iPhone 5

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.

How to get IMEI on iPhone?

You can't get IMEI on iPhone anymore. You may have to use UDID instead. See other answers.


In the past, you could use the header file "Message/NetworkController.h" posted on ericasadun.com.
http://ericasadun.com/iPhoneDocs300/_network_controller_8h-source.html (It's been removed now)

You would add the NetworkController.h file and the private framework "Message.framework" to your project, then import that header file to use the original method I found to get the imei number:

NetworkController *ntc = [NetworkController sharedInstance];
NSString *imeistring = [ntc IMEI];

That hack doesn't work anymore. App will be rejected by Apple.

How to get IMEI number of iPhone programmatically?

You can get the UDID, but can not get the IMEI.Apple does not allow this.

Finding IMEI number using Objective-C

Apple does not allow you to identify a device any more.

UDID, MAC address and all other device identifiers are no longer accessible or allowed by Apple.

Apple suggest that you use either UUID (which you will need to store your self or), identifierForVendor or advertisingIdentifier.

Apple is now also rejecting app that use the advertisingIdentifier and not showing any advertisements apps.

Any means to get the IMEI number are using private methods, which is also not allowed by Apple anymore. And your mobile app might/will get rejected because of this.

get IMEI on iPhone with CoreTelephony?

NOTE: this does not work anymore!

Haven't tested on any new iOS.

You have to add CoreTelephony.h to your project.
Make sure the header has

int * _CTServerConnectionCopyMobileEquipmentInfo (
struct CTResult * Status,
struct __CTServerConnection * Connection,
CFMutableDictionaryRef * Dictionary
);

Then you can try this code:

#import "CoreTelephony.h"
void getImei() {
struct CTResult it;
CFMutableDictionaryRef kCTDict;
conn = _CTServerConnectionCreate(kCFAllocatorDefault, ConnectionCallback,NULL);
_CTServerConnectionCopyMobileEquipmentInfo(&it, conn, &kCTDict);
NSLog (@ "kCTDict is %@", kCTDict);
CFStringRef meid = CFDictionaryGetValue(kCTDict, CFSTR("kCTMobileEquipmentInfoMEID"));
NSLog (@ "kCTMobileEquipmentInfoMEID is %@", meid);
CFStringRef mobileId = CFDictionaryGetValue(kCTDict, CFSTR("kCTMobileEquipmentInfoCurrentMobileId"));
NSLog (@ "kCTMobileEquipmentInfoCurrentMobileId is %@", mobileId);
}

Here's the CoreTelephony.h

You can check my example project.

Note: I don't think the code works on the simulator and your app might get rejected.

Alternate to IMEI

There are a few alternatives to the IMEI or MAC address that Apple now provide.

One such is [[UIDevice currentDevice] identifierForVendor].

From Apple's documentation.

An alphanumeric string that uniquely identifies a device to the app’s vendor.
The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

There is another alternative which, if you're implementing a system to serve advertisements, you need to use [ASIdentifierManager advertisingIdentifier] according to their documentation.

I find that identifierForVendor is usually enough to implement a security layer, especially when you have a server side component that maintains a list of users and identifiers used.

You can also generate a UUID off of the identifierForVendor as seen below.

Objective-C:

NSString *generateUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

Swift 3:

let generateUUID = UIDevice.current.identifierForVendor?.uuidString

This should absolutely be enough for what you require.



Related Topics



Leave a reply



Submit