我正在尝试构建一个返回以下信息的应用程序:
- IMEI
- 国际商会
- IMSI
我看到我可以使用 CoreTelephony,但我开始怀疑:要使用这些头文件(从 class-dump 导入 CoreTelephony.h),设备必须越狱吗?
如果不是,CoreTelephony 仅对iOS6有效吗?
我就是这样做的:
CTServerConnectionRef conn;
void ConnectionCallback(CTServerConnectionRef connection, CFStringRef string, CFDictionaryRef dictionary, void *data) {
NSLog(@"ConnectionCallback");
CFShow(dictionary);
}
- (NSString *)coreTelephonyInfoForKey:(const NSString *)key {
NSString *retVal = nil;
conn = _CTServerConnectionCreate(kCFAllocatorDefault, ConnectionCallback,NULL);
if (conn) {
struct CTResult result;
CFMutableDictionaryRef equipmentInfo = nil;
_CTServerConnectionCopyMobileEquipmentInfo(&result, conn, &equipmentInfo);
if (equipmentInfo) {
retVal = [NSString stringWithString:CFDictionaryGetValue(equipmentInfo, (__bridge const void *)(key))];
CFRelease(equipmentInfo);
}
CFRelease(conn);
}
return retVal;
}
- (NSString *)IMEI {
return [self coreTelephonyInfoForKey:@"kCTMobileEquipmentInfoIMEI"];
这是我的CoreTelephony.h