Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
997 views
in Technique[技术] by (71.8m points)

ios - get IMEI on iPhone with CoreTelephony?

I have tried the accepted answer of How to get IMEI on iPhone? but I got an empty string.

I saw somebody suggested to use CoreTelephony framework, but I am not sure how to use it to obtain the IMEI.

Any suggestion on how to use this private API?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...