Authored by 刘金林

ca info

@@ -300,6 +300,7 @@ typedef NS_ENUM(NSInteger, YHPointType) { @@ -300,6 +300,7 @@ typedef NS_ENUM(NSInteger, YHPointType) {
300 #define kCarrierCodeChinaTelecom @"2" // 中国电信 300 #define kCarrierCodeChinaTelecom @"2" // 中国电信
301 #define kCarrierCodeChinaUnicom @"3" // 中国联通 301 #define kCarrierCodeChinaUnicom @"3" // 中国联通
302 #define kCarrierCodeChinaTietong @"4" // 中国铁通 302 #define kCarrierCodeChinaTietong @"4" // 中国铁通
  303 +#define kCarrierCodeOverseas @"5" // 海外
303 304
304 //上报参数的key 305 //上报参数的key
305 #define YOHOAppReportKeyAK @"ak" 306 #define YOHOAppReportKeyAK @"ak"
@@ -320,7 +321,8 @@ typedef NS_ENUM(NSInteger, YHPointType) { @@ -320,7 +321,8 @@ typedef NS_ENUM(NSInteger, YHPointType) {
320 #define YOHOAppReportKeyPT @"pt" 321 #define YOHOAppReportKeyPT @"pt"
321 #define YOHOAppReportKeyPN @"pn" 322 #define YOHOAppReportKeyPN @"pn"
322 #define YOHOAppReportKeyPARAM @"param" 323 #define YOHOAppReportKeyPARAM @"param"
323 - 324 +#define YOHOAppReportKeyMCC @"mcc"
  325 +#define YOHOAppReportKeyMNC @"mnc"
324 326
325 #define YOHOAppReportDefaultAPPKey @"yohobuy_ios" 327 #define YOHOAppReportDefaultAPPKey @"yohobuy_ios"
326 328
@@ -134,6 +134,8 @@ @@ -134,6 +134,8 @@
134 IsStrEmpty(appInfo.ts)?@"":appInfo.ts,YOHOAppReportKeyTS, 134 IsStrEmpty(appInfo.ts)?@"":appInfo.ts,YOHOAppReportKeyTS,
135 IsStrEmpty(appInfo.uid)?@"":appInfo.uid,YOHOAppReportKeyUID, 135 IsStrEmpty(appInfo.uid)?@"":appInfo.uid,YOHOAppReportKeyUID,
136 IsStrEmpty(appInfo.sid)?@"":appInfo.sid,YOHOAppReportKeySID, 136 IsStrEmpty(appInfo.sid)?@"":appInfo.sid,YOHOAppReportKeySID,
  137 + IsStrEmpty(appInfo.mcc)?@"":appInfo.mcc,YOHOAppReportKeyMCC,
  138 + IsStrEmpty(appInfo.mnc)?@"":appInfo.mnc,YOHOAppReportKeyMNC,
137 nil]; 139 nil];
138 return commonInfo; 140 return commonInfo;
139 } 141 }
@@ -25,6 +25,8 @@ @@ -25,6 +25,8 @@
25 @property (copy, nonatomic) NSString *sid; // 会话id(由设备标识和启动时间戳做md5) 25 @property (copy, nonatomic) NSString *sid; // 会话id(由设备标识和启动时间戳做md5)
26 @property (copy, nonatomic) NSString *ts; // 时间戳 26 @property (copy, nonatomic) NSString *ts; // 时间戳
27 @property (copy, nonatomic) NSString *idfa; //设备idfa标识 27 @property (copy, nonatomic) NSString *idfa; //设备idfa标识
  28 +@property (copy, nonatomic) NSString *mcc; //移动设备国家代码(Mobile Country Code,MCC)
  29 +@property (copy, nonatomic) NSString *mnc; //运营商码 移动设备网络代码英语:Mobile Network Code,MNC
28 30
29 -(void)resetSessionID; 31 -(void)resetSessionID;
30 32
@@ -26,8 +26,8 @@ @@ -26,8 +26,8 @@
26 self = [super init]; 26 self = [super init];
27 if (self) { 27 if (self) {
28 self.ps = @"0"; 28 self.ps = @"0";
29 - self.ca = [self getCurrentCa];  
30 self.idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; 29 self.idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
  30 + [self loadCarrierInfo];
31 } 31 }
32 32
33 return self; 33 return self;
@@ -39,6 +39,13 @@ @@ -39,6 +39,13 @@
39 } 39 }
40 } 40 }
41 41
  42 +- (NSString *)ca {
  43 + if (!_ca || [_ca isEqualToString:kCarrierCodeChinaUnknown]) {
  44 + [self loadCarrierInfo];
  45 + }
  46 + return _ca;
  47 +}
  48 +
42 - (NSString*)ch 49 - (NSString*)ch
43 { 50 {
44 _ch = [[YHEventReport sharedInstance] channelId]; 51 _ch = [[YHEventReport sharedInstance] channelId];
@@ -125,23 +132,40 @@ @@ -125,23 +132,40 @@
125 return _net; 132 return _net;
126 } 133 }
127 134
128 -- (NSString *)getCurrentCa 135 +- (void)loadCarrierInfo
129 { 136 {
  137 + NSString *currentCa = kCarrierCodeChinaUnknown;
130 CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init]; 138 CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
131 CTCarrier *carrier = [netInfo subscriberCellularProvider]; 139 CTCarrier *carrier = [netInfo subscriberCellularProvider];
132 -  
133 - // 中国移动  
134 - if ([carrier.mobileNetworkCode isEqualToString:@"00"] || [carrier.mobileNetworkCode isEqualToString:@"02"] || [carrier.mobileNetworkCode isEqualToString:@"07"]) {  
135 - return kCarrierCodeChinaMobile;  
136 - } else if([carrier.mobileNetworkCode isEqualToString:@"01"] || [carrier.mobileNetworkCode isEqualToString:@"06"]) { // 中国联通  
137 - return kCarrierCodeChinaUnicom;  
138 - }else if([carrier.mobileNetworkCode isEqualToString:@"03"] || [carrier.mobileNetworkCode isEqualToString:@"05"]) { // 中国电信  
139 - return kCarrierCodeChinaTelecom;  
140 - } else if([carrier.mobileNetworkCode isEqualToString:@"20"]){ // 中国铁通  
141 - return kCarrierCodeChinaTietong; 140 + NSString *const chinaMCC = @"460";
  141 + _mcc = [carrier.mobileCountryCode copy] ?: @"";
  142 + _mnc = [carrier.mobileNetworkCode copy] ?: @"";
  143 + if (carrier.mobileCountryCode) {
  144 + if ([carrier.mobileCountryCode isEqualToString:chinaMCC]) {
  145 + NSArray *const chinaMobile = @[ @"00", @"02", @"07" ];// 中国移动
  146 + NSArray *const chinaUnicom = @[ @"01", @"06", @"09" ];// 中国联通
  147 + NSArray *const chinaTelecom = @[ @"03", @"05", @"11" ];// 中国电信
  148 + NSArray *const chinaTietong = @[ @"20" ];// 中国铁通
  149 + NSString *const mnc = [carrier.mobileNetworkCode copy];
  150 + if ([chinaMobile containsObject:mnc]) {
  151 + currentCa = kCarrierCodeChinaMobile;
  152 + } else if ([chinaUnicom containsObject:mnc]) {
  153 + currentCa = kCarrierCodeChinaUnicom;
  154 + } else if ([chinaTelecom containsObject:mnc]) {
  155 + currentCa = kCarrierCodeChinaTelecom;
  156 + } else if ([chinaTietong containsObject:mnc]) {
  157 + currentCa = kCarrierCodeChinaTietong;
  158 + }
  159 + } else {
  160 + currentCa = kCarrierCodeOverseas;
  161 + }
  162 + }
  163 + if ([currentCa isEqualToString:kCarrierCodeChinaUnknown]) {
  164 + currentCa = [[NSUserDefaults standardUserDefaults] objectForKey:NSStringFromSelector(_cmd)] ?: kCarrierCodeChinaUnknown;
142 } else { 165 } else {
143 - return kCarrierCodeChinaUnknown; 166 + [[NSUserDefaults standardUserDefaults] setObject:currentCa forKey:NSStringFromSelector(_cmd)];
144 } 167 }
  168 + _ca = [currentCa copy];
145 } 169 }
146 170
147 -(NSString *)uid{ 171 -(NSString *)uid{
@@ -52,7 +52,7 @@ static NSString *kParamKeyType = @"type"; @@ -52,7 +52,7 @@ static NSString *kParamKeyType = @"type";
52 if (self) { 52 if (self) {
53 self.timeInterval = 30; 53 self.timeInterval = 30;
54 self.mode = YHEventReportStrategyInterval; 54 self.mode = YHEventReportStrategyInterval;
55 - 55 + self.performanceAppInfo = [[YH_PerformanceAppInfo alloc] init];
56 self.timer = [NSTimer timerWithTimeInterval:self.timeInterval target:self selector:@selector(timerAction) userInfo:nil repeats:YES]; 56 self.timer = [NSTimer timerWithTimeInterval:self.timeInterval target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
57 [[NSRunLoop mainRunLoop] addTimer:self.timer forMode: NSRunLoopCommonModes]; 57 [[NSRunLoop mainRunLoop] addTimer:self.timer forMode: NSRunLoopCommonModes];
58 58
@@ -94,20 +94,6 @@ static NSString *kParamKeyType = @"type"; @@ -94,20 +94,6 @@ static NSString *kParamKeyType = @"type";
94 } 94 }
95 95
96 #pragma mark - Getters 96 #pragma mark - Getters
97 --(YH_PerformanceAppInfo *)performanceAppInfo{  
98 - if (!_performanceAppInfo) {  
99 - _performanceAppInfo = [[YH_PerformanceAppInfo alloc] init];  
100 - }  
101 - return _performanceAppInfo;  
102 -}  
103 -  
104 -//- (NSMutableArray*)eventCacheArray  
105 -//{  
106 -// if (_eventCacheArray == nil) {  
107 -// _eventCacheArray = [[NSMutableArray alloc]initWithCapacity:0];  
108 -// }  
109 -// return _eventCacheArray;  
110 -//}  
111 97
112 - (NSMutableArray*)performanceCacheArray 98 - (NSMutableArray*)performanceCacheArray
113 { 99 {