How to get IMEI on iPhone 5

14,662

Solution 1

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.

Solution 2

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.

Solution 3

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

Share:
14,662

Related videos on Youtube

InViZz
Author by

InViZz

Updated on June 04, 2022

Comments

  • InViZz
    InViZz almost 2 years

    I'm develop application for jailbroken iOS devices. I use https://github.com/erica/uidevice-extension/blob/master/UIDevice-IOKitExtensions.m to get IMEI, but on iPhone 5 this solution does not work(return empty string). Is there any way to get IMEI on iPhone 5(iOS 6.1.2)?

  • Joseandro Luiz
    Joseandro Luiz over 10 years
    Sadly, none of those methods will return the IMEI on iOS7
  • creker
    creker over 10 years
    @Mobster, these APIs are probably protected by entitlement in iOS 7. I think it's com.apple.coretelephony.Identity.get.
  • Joseandro Luiz
    Joseandro Luiz over 10 years
    @creker, to use the com.apple.coretelephony.Identity.get, the device must be jailbroken, right?
  • Joseandro Luiz
    Joseandro Luiz over 10 years
    By the way, do you have the full list of entitlements we'd need to use to get the IMEI/MEID on iOS7 ? Thanks :)
  • creker
    creker over 10 years
    Yes, device must be jailbroken. As for entitlement, it's just a guess. I looked at Preferences app (it has access to this kind of information, including IMEI) entitlements, found one that's looks like it has something to do with IMEI. Preferences app in iOS 6 doesn't have this entitlement so I assumed it's the reason why these APIs stopped working. We just have to wait for jailbrake to test it.
  • Ahad Khan
    Ahad Khan over 9 years
    com.apple.coretelephony.Identity.get is working fine on iOS 7.0.6 but not working on iOS 7.1.2. Do I need to sign app with another entitlement?
  • creker
    creker over 9 years
    @AhadKhan, I will look into it. I didn't know it doesn't work any more.
  • Ahad Khan
    Ahad Khan over 9 years
    @creker Have you find any clue for finding IMEI in 7.1.2?
  • Sergey Grischyov
    Sergey Grischyov about 9 years
    Any news on this topic in 2015? Anyone?
  • creker
    creker about 9 years
    @SergiusGee, everything works like it did, including iOS 8. I usually update my answers when new jailbroken iOS comes out. Either by myself or when somebody tells me it stopped working.
  • Sergey Grischyov
    Sergey Grischyov about 9 years
    @creker That's true but only for the jailbroken devices. How about using Private APIs without jailbreak?
  • creker
    creker about 9 years
    @SergiusGee, there is no way. Every method/function I came across to retrieve IMEI doesn't work without jailbreak. Apple protected everything with entitlements which require jailbreak.
  • Sergey Grischyov
    Sergey Grischyov about 9 years
    @creker had the same conclusion. Anyway, thanks for your great work! really awesome!
  • WildMassacre
    WildMassacre almost 9 years
    Probably you made a typo. "UUIDstring" and "identity". This code is the correct one: NSUUID *UUID = [[UIDevice currentDevice] identifierForVendor]; NSString *stringUUID = [UUID UUIDString]; Work on iOS 8.3