YH_PerformanceAppInfo.m
6.31 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// YH_PerformanceAppInfo.m
// YH_Mall
//
// Created by John Tai on 22/8/2017.
// Copyright © 2017 YOHO. All rights reserved.
//
#import "YH_PerformanceAppInfo.h"
#import "YH_SessionUtility.h"
#import "YHEventReportMacros.h"
#import "JTSHardwareInfo.h"
#import "YH_Reachability.h"
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <UIKit/UIKit.h>
#import "YH_EventUtil.h"
#import "YHEventReport.h"
#import "NSString+ER_URL.h"
#import <UserNotifications/UserNotifications.h>
#import "YH_Reachability.h"
#import "OpenUDID.h"
@implementation YH_PerformanceAppInfo
- (id)init {
self = [super init];
if (self) {
_ps = @"0";
_net = @"0";
[self update];
}
return self;
}
- (void)update {
self.ch = [[YHEventReport sharedInstance] channelId];
self.udid = [OpenUDID value];
self.os = @"iOS";
self.osv = [[UIDevice currentDevice] systemVersion] ?: @"Unknown";
self.av =[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: @"";
self.ab = [[NSBundle mainBundle] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey] ?: @"";
[self loadCarrierInfo];
[self loadPushStatus];
[self loadDm];
}
- (void)loadPushStatus {
if (IOS10) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings) {
switch (settings.authorizationStatus) {
case UNAuthorizationStatusNotDetermined:
case UNAuthorizationStatusDenied:
self.ps = @"0";
break;
default:
self.ps = @"1";
break;
}
}];
} else {
if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone) {
self.ps = @"1";
}else {
self.ps = @"0";
}
}
}
-(void)loadDm{
if (!_dm) {
_dm = [JTSHardwareInfo hardwareIdentifier];
NSRange range = [_dm rangeOfString:@","];
if (range.location != NSNotFound) {
_dm = [_dm stringByReplacingCharactersInRange:range withString:@"_"];
}
if (!_dm) {
_dm = @"";
}
}
}
- (void)loadCarrierInfo
{
NSString *currentCa = kCarrierCodeChinaUnknown;
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *const chinaMCC = @"460";
_mcc = [carrier.mobileCountryCode copy] ?: @"";
_mnc = [carrier.mobileNetworkCode copy] ?: @"";
if (carrier.mobileCountryCode) {
if ([carrier.mobileCountryCode isEqualToString:chinaMCC]) {
NSArray *const chinaMobile = @[ @"00", @"02", @"07" , @"08"];// 中国移动
NSArray *const chinaUnicom = @[ @"01", @"06", @"09" ];// 中国联通
NSArray *const chinaTelecom = @[ @"03", @"05", @"11" ];// 中国电信
NSArray *const chinaTietong = @[ @"20" ];// 中国铁通
NSString *const mnc = [carrier.mobileNetworkCode copy];
if ([chinaMobile containsObject:mnc]) {
currentCa = kCarrierCodeChinaMobile;
} else if ([chinaUnicom containsObject:mnc]) {
currentCa = kCarrierCodeChinaUnicom;
} else if ([chinaTelecom containsObject:mnc]) {
currentCa = kCarrierCodeChinaTelecom;
} else if ([chinaTietong containsObject:mnc]) {
currentCa = kCarrierCodeChinaTietong;
}
} else {
currentCa = kCarrierCodeOverseas;
}
}
if ([currentCa isEqualToString:kCarrierCodeChinaUnknown]) {
currentCa = [[NSUserDefaults standardUserDefaults] objectForKey:NSStringFromSelector(_cmd)] ?: kCarrierCodeChinaUnknown;
} else {
[[NSUserDefaults standardUserDefaults] setObject:currentCa forKey:NSStringFromSelector(_cmd)];
}
_ca = [currentCa copy];
}
- (void)updateNetStatusWithReachability:(YH_Reachability *)reachability {
if (reachability.currentReachabilityStatus == YHNetworkStatusNotReachable) {
self.net = YOHOAppReportKeykNetWorkStatusUnknow;
} else if (reachability.currentReachabilityStatus == YHNetworkStatusReachableViaWiFi) {
self.net = YOHOAppReportKeykNetWorkStatusWIFI;
} else if (reachability.currentReachabilityStatus == YHNetworkStatusReachableViaWWAN) {
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
if ([netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
self.net = YOHOAppReportKeykNetWorkStatus2G;
} else if([netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]
|| [netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
self.net = YOHOAppReportKeykNetWorkStatus3G;
} else if([netInfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
self.net = YOHOAppReportKeykNetWorkStatus4G;
} else {
self.net = YOHOAppReportKeykNetWorkStatusUnknow;
}
}
}
-(NSString *)uid{
_uid = [[YHEventReport sharedInstance] uid];
return [_uid er_md5String];
}
-(NSString *)sid{
return [YH_SessionUtility sharedInstance].session;
}
-(NSString *)ts{
NSTimeInterval date = [[NSDate date] timeIntervalSince1970]*1000;
int num = (arc4random() % 1000000);
return [NSString stringWithFormat:@"%.0f%.6d", date,num]?:@"";
}
@end