-
Notifications
You must be signed in to change notification settings - Fork 19
/
UIDevice+CoreTelephonyCategory.m
83 lines (67 loc) · 2.43 KB
/
UIDevice+CoreTelephonyCategory.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// UIDevice+CoreTelephonyCategory.m
// EquipmentInfo
//
// Created by Ray Zhang on 13-1-29.
// Copyright (c) 2013年 Ray Zhang. All rights reserved.
//
// This Category Depand on Core Telephony Framework.
//
#import "UIDevice+CoreTelephonyCategory.h"
typedef struct CTResult {
int flag;
int a;
} CTResult;
typedef const struct __CTServerConnection * CTServerConnectionRef;
extern CTServerConnectionRef _CTServerConnectionCreate(CFAllocatorRef, int (*)(void *, CFStringRef, CFDictionaryRef, void *), int *);
#ifdef __arm__
extern void _CTServerConnectionCopyMobileEquipmentInfo(CTResult *status, CTServerConnectionRef connection, CFMutableDictionaryRef *equipmentInfo);
#elif defined __arm64__
extern void _CTServerConnectionCopyMobileEquipmentInfo(CTServerConnectionRef connection, CFMutableDictionaryRef *equipmentInfo, NSInteger *unknown);
#endif
static int callback(void *connection, CFStringRef string, CFDictionaryRef dictionary, void *data) {
return 0;
}
@implementation UIDevice (CoreTelephony)
// Core Telephony Device Information
+ (NSString *)coreTelephonyInfoForKey:(const NSString *)key {
NSString *retVal = nil;
CTServerConnectionRef ctsc = _CTServerConnectionCreate(kCFAllocatorDefault, callback, NULL);
if (ctsc) {
CFMutableDictionaryRef equipmentInfo = nil;
#ifdef __arm__
struct CTResult result;
_CTServerConnectionCopyMobileEquipmentInfo(&result, ctsc, &equipmentInfo);
#elif defined __arm64__
_CTServerConnectionCopyMobileEquipmentInfo(ctsc, &equipmentInfo, NULL);
#endif
if (equipmentInfo) {
CFStringRef value = CFDictionaryGetValue(equipmentInfo, key);
if (value) {
retVal = [NSString stringWithString:(id)value];
}
CFRelease(equipmentInfo);
}
CFRelease(ctsc);
}
return retVal;
}
+ (NSString *)IMEI {
return [self coreTelephonyInfoForKey:@"kCTMobileEquipmentInfoIMEI"];
}
+ (NSString *)CMID {
return [self coreTelephonyInfoForKey:@"kCTMobileEquipmentInfoCurrentMobileId"];
}
+ (NSString *)ICCID {
return [self coreTelephonyInfoForKey:@"kCTMobileEquipmentInfoICCID"];
}
+ (NSString *)MEID {
return [self coreTelephonyInfoForKey:@"kCTMobileEquipmentInfoMEID"];
}
+ (NSString *)IMSI {
return [self coreTelephonyInfoForKey:@"kCTMobileEquipmentInfoIMSI"];
}
+ (NSString *)CSID {
return [self coreTelephonyInfoForKey:@"kCTMobileEquipmentInfoCurrentSubscriberId"];
}
@end