|
@@ -7,7 +7,6 @@ |
|
@@ -7,7 +7,6 @@ |
7
|
//
|
7
|
//
|
8
|
|
8
|
|
9
|
#import "YH_EventCacheManager.h"
|
9
|
#import "YH_EventCacheManager.h"
|
10
|
-#import "YH_EventCacheFile.h"
|
|
|
11
|
#import <UIKit/UIKit.h>
|
10
|
#import <UIKit/UIKit.h>
|
12
|
#import "YH_EventDataSession.h"
|
11
|
#import "YH_EventDataSession.h"
|
13
|
#import "YH_EventDataFactory.h"
|
12
|
#import "YH_EventDataFactory.h"
|
|
@@ -17,25 +16,27 @@ |
|
@@ -17,25 +16,27 @@ |
17
|
#import "YH_AnalyticEventData.h"
|
16
|
#import "YH_AnalyticEventData.h"
|
18
|
#import "YHLog.h"
|
17
|
#import "YHLog.h"
|
19
|
#import "YH_EventDataFactory.h"
|
18
|
#import "YH_EventDataFactory.h"
|
|
|
19
|
+#import <YH_FoundationKit/YH_FoundationKit.h>
|
|
|
20
|
+
|
|
|
21
|
+static NSString *const kParamKeyDevice = @"device";
|
|
|
22
|
+static NSString *const kParamKeyList = @"events";
|
|
|
23
|
+static NSString *const kParamKeyType = @"type";
|
20
|
|
24
|
|
21
|
@interface YH_EventCacheManager()
|
25
|
@interface YH_EventCacheManager()
|
22
|
|
26
|
|
23
|
-//@property (strong, nonatomic) NSMutableArray *eventCacheArray;
|
|
|
24
|
-@property (strong, nonatomic) NSMutableArray *performanceCacheArray;
|
27
|
+@property (strong, nonatomic) NSMutableArray *infoCacheArray;//cache custom & performance,click info send in realtime
|
25
|
@property (strong, nonatomic) YH_EventDataSession *eventDataSession;
|
28
|
@property (strong, nonatomic) YH_EventDataSession *eventDataSession;
|
26
|
-@property (nonatomic, assign) YHEventReportStrategy mode;
|
|
|
27
|
-@property (nonatomic,strong)YH_PerformanceAppInfo *performanceAppInfo;
|
|
|
28
|
-@property (nonatomic,strong)NSTimer *timer;
|
|
|
29
|
-@property (nonatomic,assign)long timeInterval;
|
29
|
+@property (nonatomic, assign) YHEventReportStrategy mode;
|
|
|
30
|
+@property (nonatomic,strong) YH_PerformanceAppInfo *appInfo;
|
|
|
31
|
+@property (nonatomic,strong) dispatch_source_t timer;
|
|
|
32
|
+@property (nonatomic,strong) dispatch_queue_t queue;
|
|
|
33
|
+@property (nonatomic,assign) NSUInteger timeInterval;
|
|
|
34
|
+@property (nonatomic, strong) YH_Reachability *intnetReachability;
|
30
|
|
35
|
|
31
|
@end
|
36
|
@end
|
32
|
|
37
|
|
33
|
@implementation YH_EventCacheManager
|
38
|
@implementation YH_EventCacheManager
|
34
|
|
39
|
|
35
|
-static NSString *kParamKeyDevice = @"device";
|
|
|
36
|
-static NSString *kParamKeyList = @"events";
|
|
|
37
|
-static NSString *kParamKeyType = @"type";
|
|
|
38
|
-
|
|
|
39
|
+ (YH_EventCacheManager *)sharedInstance
|
40
|
+ (YH_EventCacheManager *)sharedInstance
|
40
|
{
|
41
|
{
|
41
|
static YH_EventCacheManager *sharedInstance = nil;
|
42
|
static YH_EventCacheManager *sharedInstance = nil;
|
|
@@ -50,67 +51,33 @@ static NSString *kParamKeyType = @"type"; |
|
@@ -50,67 +51,33 @@ static NSString *kParamKeyType = @"type"; |
50
|
{
|
51
|
{
|
51
|
self = [super init];
|
52
|
self = [super init];
|
52
|
if (self) {
|
53
|
if (self) {
|
53
|
- self.timeInterval = 30;
|
|
|
54
|
- self.mode = YHEventReportStrategyInterval;
|
|
|
55
|
- self.performanceAppInfo = [[YH_PerformanceAppInfo alloc] init];
|
|
|
56
|
- self.timer = [NSTimer timerWithTimeInterval:self.timeInterval target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
|
|
|
57
|
- [[NSRunLoop mainRunLoop] addTimer:self.timer forMode: NSRunLoopCommonModes];
|
|
|
58
|
-
|
|
|
59
|
- [[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
60
|
- selector:@selector(handleMemoryWarning)
|
|
|
61
|
- name:UIApplicationDidReceiveMemoryWarningNotification
|
|
|
62
|
- object:nil];
|
|
|
63
|
-
|
|
|
64
|
- [[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
65
|
- selector:@selector(handleApplicationBackgrounding)
|
|
|
66
|
- name:UIApplicationDidEnterBackgroundNotification
|
|
|
67
|
- object:nil];
|
|
|
68
|
-
|
|
|
69
|
- [[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
70
|
- selector:@selector(handleDidFinishLaunch)
|
|
|
71
|
- name:UIApplicationDidFinishLaunchingNotification
|
|
|
72
|
- object:nil];
|
|
|
73
|
- [[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
74
|
- selector:@selector(handleTerminate)
|
|
|
75
|
- name:UIApplicationWillTerminateNotification
|
|
|
76
|
- object:nil];
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshPushStatus) name:UIApplicationWillEnterForegroundNotification object:nil];
|
|
|
82
|
-
|
|
|
83
|
- [self refreshPushStatus];
|
|
|
84
|
- [[YH_Reachability reachabilityForInternetConnection] startNotifier];
|
54
|
+ _timeInterval = 30;
|
|
|
55
|
+ _mode = YHEventReportStrategyInterval;
|
|
|
56
|
+ _appInfo = [[YH_PerformanceAppInfo alloc] init];
|
|
|
57
|
+ _eventDataSession = [[YH_EventDataSession alloc] init];
|
|
|
58
|
+ _infoCacheArray = [NSMutableArray array];
|
|
|
59
|
+ _queue = yh_gcdSerialQueue(@"cn.yoho.buy.eventReport.serial");
|
|
|
60
|
+ _intnetReachability = [YH_Reachability reachabilityForInternetConnection];
|
|
|
61
|
+ [_intnetReachability startNotifier];
|
|
|
62
|
+ [self startTimer];
|
|
|
63
|
+ [self yh_observeNotificationName:UIApplicationDidReceiveMemoryWarningNotification action:@selector(handleMemoryWarning)];
|
|
|
64
|
+ [self yh_observeNotificationName:UIApplicationDidEnterBackgroundNotification action:@selector(handleApplicationBackgrounding)];
|
|
|
65
|
+ [self yh_observeNotificationName:UIApplicationWillEnterForegroundNotification action:@selector(handleApplicationForerounding)];
|
|
|
66
|
+ [self yh_observeNotificationName:UIApplicationDidFinishLaunchingNotification action:@selector(handleDidFinishLaunch)];
|
|
|
67
|
+ [self yh_observeNotificationName:UIApplicationWillTerminateNotification action:@selector(handleTerminate)];
|
|
|
68
|
+ [self yh_observeNotificationName:UIApplicationWillEnterForegroundNotification action:@selector(refreshAppInfo)];
|
|
|
69
|
+ [self yh_observeNotificationName:kYHReachabilityChangedNotification action:@selector(networkStateChange:)];
|
85
|
}
|
70
|
}
|
86
|
return self;
|
71
|
return self;
|
87
|
}
|
72
|
}
|
88
|
|
73
|
|
89
|
- (void)dealloc
|
74
|
- (void)dealloc
|
90
|
{
|
75
|
{
|
91
|
- [self.timer invalidate];
|
|
|
92
|
- [[YH_Reachability reachabilityForInternetConnection] stopNotifier];
|
76
|
+ [self cancelTimer];
|
|
|
77
|
+ [_intnetReachability stopNotifier];
|
93
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
78
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
94
|
}
|
79
|
}
|
95
|
|
80
|
|
96
|
-#pragma mark - Getters
|
|
|
97
|
-
|
|
|
98
|
-- (NSMutableArray*)performanceCacheArray
|
|
|
99
|
-{
|
|
|
100
|
- if (_performanceCacheArray == nil) {
|
|
|
101
|
- _performanceCacheArray = [[NSMutableArray alloc]initWithCapacity:0];
|
|
|
102
|
- }
|
|
|
103
|
- return _performanceCacheArray;
|
|
|
104
|
-}
|
|
|
105
|
-
|
|
|
106
|
-- (YH_EventDataSession*)eventDataSession
|
|
|
107
|
-{
|
|
|
108
|
- if (_eventDataSession == nil) {
|
|
|
109
|
- _eventDataSession = [[YH_EventDataSession alloc]init];
|
|
|
110
|
- }
|
|
|
111
|
- return _eventDataSession;
|
|
|
112
|
-}
|
|
|
113
|
-
|
|
|
114
|
#pragma mark - public
|
81
|
#pragma mark - public
|
115
|
|
82
|
|
116
|
- (void)pushUIControlEvent:(NSString *)viewPath title:(NSString *)title content:(NSString *)content yh_pageName:(NSString *)yh_pageName yh_typeId:(NSString *)yh_typeId alias: (NSString *)yh_Alias
|
83
|
- (void)pushUIControlEvent:(NSString *)viewPath title:(NSString *)title content:(NSString *)content yh_pageName:(NSString *)yh_pageName yh_typeId:(NSString *)yh_typeId alias: (NSString *)yh_Alias
|
|
@@ -119,7 +86,6 @@ static NSString *kParamKeyType = @"type"; |
|
@@ -119,7 +86,6 @@ static NSString *kParamKeyType = @"type"; |
119
|
YHLog(@"UIControlEvent: viewPath can't empty!!!");
|
86
|
YHLog(@"UIControlEvent: viewPath can't empty!!!");
|
120
|
return;
|
87
|
return;
|
121
|
}
|
88
|
}
|
122
|
-
|
|
|
123
|
NSDictionary *param = @{
|
89
|
NSDictionary *param = @{
|
124
|
kYHEventReportClickViewPath: viewPath,
|
90
|
kYHEventReportClickViewPath: viewPath,
|
125
|
kYHEventReportClickTitle: title ?: @"",
|
91
|
kYHEventReportClickTitle: title ?: @"",
|
|
@@ -128,16 +94,15 @@ static NSString *kParamKeyType = @"type"; |
|
@@ -128,16 +94,15 @@ static NSString *kParamKeyType = @"type"; |
128
|
kYHEventReportClickVCPageName: yh_pageName?:@"",
|
94
|
kYHEventReportClickVCPageName: yh_pageName?:@"",
|
129
|
kYHEventReportClickVCAlias: yh_Alias?:@"",
|
95
|
kYHEventReportClickVCAlias: yh_Alias?:@"",
|
130
|
};
|
96
|
};
|
131
|
-
|
|
|
132
|
YHLog(@"UIControlEvent: %@", param);
|
97
|
YHLog(@"UIControlEvent: %@", param);
|
133
|
-
|
|
|
134
|
[self pushEventData:param];
|
98
|
[self pushEventData:param];
|
135
|
-
|
|
|
136
|
}
|
99
|
}
|
137
|
|
100
|
|
138
|
- (void)pushEventData:(NSDictionary*)data
|
101
|
- (void)pushEventData:(NSDictionary*)data
|
139
|
{
|
102
|
{
|
140
|
- [self pushData:[[YH_AnalyticEventData sharedInstance] analyticEventParameters:data] dataType:YHEventReportDataTypeClickEvent];
|
103
|
+ dispatch_async(self.queue, ^{
|
|
|
104
|
+ [self pushData:[[YH_AnalyticEventData sharedInstance] analyticEventParameters:data] dataType:YHEventReportDataTypeClickEvent];
|
|
|
105
|
+ });
|
141
|
}
|
106
|
}
|
142
|
|
107
|
|
143
|
- (void)pushPerformanceData:(NSDictionary*)data pointName:(YHEventReportPointName)name
|
108
|
- (void)pushPerformanceData:(NSDictionary*)data pointName:(YHEventReportPointName)name
|
|
@@ -146,19 +111,18 @@ static NSString *kParamKeyType = @"type"; |
|
@@ -146,19 +111,18 @@ static NSString *kParamKeyType = @"type"; |
146
|
[performanceDic setObject:@"PERFORMANCE" forKey:YOHOAppReportKeyPT];
|
111
|
[performanceDic setObject:@"PERFORMANCE" forKey:YOHOAppReportKeyPT];
|
147
|
[performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
|
112
|
[performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
|
148
|
|
113
|
|
149
|
- NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.performanceAppInfo]mutableCopy];
|
114
|
+ NSMutableDictionary *eventDic = [NSMutableDictionary dictionary];
|
150
|
|
115
|
|
151
|
- if (!IsDictionaryClass(eventDic)) {
|
|
|
152
|
- return;
|
|
|
153
|
- }
|
|
|
154
|
if (IsDictionaryClass(performanceDic)) {
|
116
|
if (IsDictionaryClass(performanceDic)) {
|
155
|
[eventDic addEntriesFromDictionary:performanceDic];
|
117
|
[eventDic addEntriesFromDictionary:performanceDic];
|
156
|
}
|
118
|
}
|
157
|
- if (IsDictionaryClass(eventDic)) {
|
119
|
+ if (IsDictionaryClass(data)) {
|
158
|
[eventDic setObject:data forKey:YOHOAppReportKeyPARAM];
|
120
|
[eventDic setObject:data forKey:YOHOAppReportKeyPARAM];
|
159
|
}
|
121
|
}
|
160
|
-
|
|
|
161
|
- [self pushData:eventDic dataType:YHEventReportDataTypePerformance];
|
122
|
+ dispatch_async(self.queue, ^{
|
|
|
123
|
+ [eventDic addEntriesFromDictionary:[YH_EventDataFactory factoryEventAppInfo:self.appInfo]];
|
|
|
124
|
+ [self pushData:eventDic dataType:YHEventReportDataTypePerformance];
|
|
|
125
|
+ });
|
162
|
}
|
126
|
}
|
163
|
|
127
|
|
164
|
- (void)pushCustomData:(NSDictionary*)data pointType:(YHPointType)type pointName:(YHEventReportPointName)name{
|
128
|
- (void)pushCustomData:(NSDictionary*)data pointType:(YHPointType)type pointName:(YHEventReportPointName)name{
|
|
@@ -166,103 +130,96 @@ static NSString *kParamKeyType = @"type"; |
|
@@ -166,103 +130,96 @@ static NSString *kParamKeyType = @"type"; |
166
|
[performanceDic setObject:[YH_EventDataFactory getPointType:type] forKey:YOHOAppReportKeyPT];
|
130
|
[performanceDic setObject:[YH_EventDataFactory getPointType:type] forKey:YOHOAppReportKeyPT];
|
167
|
[performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
|
131
|
[performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
|
168
|
|
132
|
|
169
|
- NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.performanceAppInfo]mutableCopy];
|
|
|
170
|
-
|
|
|
171
|
- if (!IsDictionaryClass(eventDic)) {
|
|
|
172
|
- return;
|
|
|
173
|
- }
|
|
|
174
|
- if (IsDictionaryClass(performanceDic)) {
|
133
|
+ dispatch_async(self.queue, ^{
|
|
|
134
|
+ NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.appInfo] mutableCopy];
|
175
|
[eventDic addEntriesFromDictionary:performanceDic];
|
135
|
[eventDic addEntriesFromDictionary:performanceDic];
|
176
|
- }
|
|
|
177
|
-
|
|
|
178
|
- switch (type) {
|
|
|
179
|
- case YHPT_NETWORK:
|
136
|
+
|
|
|
137
|
+ switch (type) {
|
|
|
138
|
+ case YHPT_NETWORK:
|
180
|
{
|
139
|
{
|
181
|
- [self.eventDataSession getbaiduNetStatus:eventDic completionBlock:^(NSTimeInterval cts, NSInteger errCode) {
|
|
|
182
|
- NSMutableDictionary *appendDict = [[NSMutableDictionary alloc] initWithDictionary:data];
|
|
|
183
|
-
|
|
|
184
|
- [appendDict setValue:[NSString stringWithFormat:@"%zd",errCode] forKey:YOHOAppReportKeyJsonKeyErrorTEC];
|
|
|
185
|
- [appendDict setValue:[NSString stringWithFormat:@"%ld",(long)cts] forKey:YOHOAppReportKeyJsonKeyErrorCTS];
|
|
|
186
|
- [eventDic setValue:appendDict forKey:YOHOAppReportKeyPARAM];
|
|
|
187
|
-
|
|
|
188
|
- [self pushData:eventDic dataType:YHEventReportDataTypeCustom];
|
|
|
189
|
- }];
|
140
|
+ [self checkBaiduStatusWithEventData:eventDic customData:data];
|
190
|
}
|
141
|
}
|
191
|
- break;
|
|
|
192
|
- case YHPT_AD:
|
142
|
+ break;
|
|
|
143
|
+ case YHPT_AD:
|
193
|
{
|
144
|
{
|
194
|
if ([data valueForKey:YOHOAppReportKeyJsonKeyErrorTEC]) {
|
145
|
if ([data valueForKey:YOHOAppReportKeyJsonKeyErrorTEC]) {
|
195
|
- [self.eventDataSession getbaiduNetStatus:eventDic completionBlock:^(NSTimeInterval cts, NSInteger errCode) {
|
|
|
196
|
- NSMutableDictionary *appendDict = [[NSMutableDictionary alloc] initWithDictionary:data];
|
|
|
197
|
-
|
|
|
198
|
- [appendDict setValue:[NSString stringWithFormat:@"%zd",errCode] forKey:YOHOAppReportKeyJsonKeyErrorTEC];
|
|
|
199
|
- [appendDict setValue:[NSString stringWithFormat:@"%ld",(long)cts] forKey:YOHOAppReportKeyJsonKeyErrorCTS];
|
|
|
200
|
- [eventDic setValue:appendDict forKey:YOHOAppReportKeyPARAM];
|
|
|
201
|
-
|
|
|
202
|
- [self pushData:eventDic dataType:YHEventReportDataTypeCustom];
|
|
|
203
|
- }];
|
146
|
+ [self checkBaiduStatusWithEventData:eventDic customData:data];
|
204
|
} else {
|
147
|
} else {
|
205
|
[eventDic setValue:data forKey:YOHOAppReportKeyPARAM];
|
148
|
[eventDic setValue:data forKey:YOHOAppReportKeyPARAM];
|
206
|
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
|
149
|
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
|
207
|
}
|
150
|
}
|
208
|
}
|
151
|
}
|
209
|
- break;
|
|
|
210
|
- default:
|
152
|
+ break;
|
|
|
153
|
+ default:
|
211
|
{
|
154
|
{
|
212
|
[eventDic setValue:data forKey:YOHOAppReportKeyPARAM];
|
155
|
[eventDic setValue:data forKey:YOHOAppReportKeyPARAM];
|
213
|
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
|
156
|
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
|
214
|
}
|
157
|
}
|
215
|
- break;
|
|
|
216
|
- }
|
158
|
+ break;
|
|
|
159
|
+ }
|
|
|
160
|
+ });
|
217
|
}
|
161
|
}
|
218
|
|
162
|
|
219
|
-- (void)pushCrashData:(NSDictionary*)data{
|
|
|
220
|
- NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.performanceAppInfo]mutableCopy];
|
|
|
221
|
-
|
|
|
222
|
- if (!IsDictionaryClass(eventDic) ||!IsDictionaryClass(data)) {
|
163
|
+- (void)checkBaiduStatusWithEventData:(NSMutableDictionary *)eventDic customData:(NSDictionary *)data {
|
|
|
164
|
+ weakify(self);
|
|
|
165
|
+ [self.eventDataSession getbaiduNetStatusWithCompletionBlock:^(NSTimeInterval cts, NSInteger errCode) {
|
|
|
166
|
+ strongify(self);
|
|
|
167
|
+ NSMutableDictionary *appendDict = [[NSMutableDictionary alloc] initWithDictionary:data];
|
|
|
168
|
+ [appendDict setValue:[NSString stringWithFormat:@"%zd",errCode] forKey:YOHOAppReportKeyJsonKeyErrorTEC];
|
|
|
169
|
+ [appendDict setValue:[NSString stringWithFormat:@"%ld",(long)cts] forKey:YOHOAppReportKeyJsonKeyErrorCTS];
|
|
|
170
|
+ [eventDic setValue:appendDict forKey:YOHOAppReportKeyPARAM];
|
|
|
171
|
+ dispatch_async(self.queue, ^{
|
|
|
172
|
+ [self pushData:eventDic dataType:YHEventReportDataTypeCustom];
|
|
|
173
|
+ });
|
|
|
174
|
+ }];
|
|
|
175
|
+}
|
|
|
176
|
+
|
|
|
177
|
+- (void)pushCrashData:(NSDictionary*)data {
|
|
|
178
|
+ if (!IsDictionaryClass(data) || data.count <= 0) {
|
223
|
return;
|
179
|
return;
|
224
|
}
|
180
|
}
|
225
|
-
|
|
|
226
|
- [eventDic addEntriesFromDictionary:data];
|
|
|
227
|
-
|
|
|
228
|
- [self pushData:[eventDic copy] dataType:YHEventReportDataTypeCustom];
|
181
|
+ dispatch_async(self.queue, ^{
|
|
|
182
|
+ NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.appInfo] mutableCopy];
|
|
|
183
|
+ [eventDic addEntriesFromDictionary:data];
|
|
|
184
|
+ [self pushData:[eventDic copy] dataType:YHEventReportDataTypeCustom];
|
|
|
185
|
+ });
|
229
|
}
|
186
|
}
|
230
|
|
187
|
|
231
|
#pragma mark - private
|
188
|
#pragma mark - private
|
232
|
- (void)pushData:(NSDictionary*)data dataType:(YHEventReportDataType)type
|
189
|
- (void)pushData:(NSDictionary*)data dataType:(YHEventReportDataType)type
|
233
|
{
|
190
|
{
|
234
|
if (type == YHEventReportDataTypeClickEvent) {
|
191
|
if (type == YHEventReportDataTypeClickEvent) {
|
235
|
- [self.eventDataSession uploadEventData:data tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
|
|
|
236
|
- }];
|
192
|
+ [self.eventDataSession uploadEventData:data tag:nil result:nil];
|
237
|
}else {
|
193
|
}else {
|
238
|
if (self.mode == YHEventReportStrategyInterval) {
|
194
|
if (self.mode == YHEventReportStrategyInterval) {
|
239
|
- @synchronized (self.performanceCacheArray) {
|
|
|
240
|
- [self.performanceCacheArray addObject:data];
|
|
|
241
|
- }
|
195
|
+ [self.infoCacheArray addObject:data];
|
242
|
}else{
|
196
|
}else{
|
|
|
197
|
+ weakify(self);
|
243
|
[self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:@[data] type:YHEventReportTrackDataTypeNONE] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
|
198
|
[self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:@[data] type:YHEventReportTrackDataTypeNONE] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
|
|
|
199
|
+ if (!isSuc) {
|
|
|
200
|
+ strongify(self);
|
|
|
201
|
+ dispatch_async(self.queue, ^{
|
|
|
202
|
+ [self.infoCacheArray addObject:data];
|
|
|
203
|
+ });
|
|
|
204
|
+ }
|
244
|
}];
|
205
|
}];
|
245
|
}
|
206
|
}
|
246
|
}
|
207
|
}
|
247
|
}
|
208
|
}
|
248
|
|
209
|
|
249
|
-- (void) startUploadMode:(YHEventReportStrategy)mode timeInterval:(long)timeIntervals;
|
210
|
+- (void)startUploadMode:(YHEventReportStrategy)mode timeInterval:(NSUInteger)timeIntervals;
|
250
|
{
|
211
|
{
|
251
|
- _mode = mode;
|
|
|
252
|
- self.timeInterval = timeIntervals;
|
|
|
253
|
- if (mode == YHEventReportStrategyInterval) {
|
|
|
254
|
- if (self.timer == nil) {
|
|
|
255
|
- //定时上传
|
|
|
256
|
- self.timer = [NSTimer timerWithTimeInterval:self.timeInterval target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
|
|
|
257
|
- [[NSRunLoop mainRunLoop] addTimer:self.timer forMode: NSRunLoopCommonModes];
|
212
|
+ dispatch_async(self.queue, ^{
|
|
|
213
|
+ _mode = mode;
|
|
|
214
|
+ if (timeIntervals > 0 && timeIntervals < 5 * 60) {
|
|
|
215
|
+ self.timeInterval = timeIntervals;
|
258
|
}
|
216
|
}
|
259
|
- }else{
|
|
|
260
|
- if (self.timer) {
|
|
|
261
|
- [self.timer invalidate];
|
|
|
262
|
- self.timer = nil;
|
217
|
+ if (mode == YHEventReportStrategyInterval) {
|
|
|
218
|
+ [self startTimer];
|
|
|
219
|
+ }else{
|
|
|
220
|
+ [self cancelTimer];
|
263
|
}
|
221
|
}
|
264
|
- }
|
|
|
265
|
-
|
222
|
+ });
|
266
|
}
|
223
|
}
|
267
|
|
224
|
|
268
|
- (NSMutableDictionary*)getPerformanceFormatData:(NSArray*)dataArray type:(YHEventReportTrackDataType)type
|
225
|
- (NSMutableDictionary*)getPerformanceFormatData:(NSArray*)dataArray type:(YHEventReportTrackDataType)type
|
|
@@ -278,135 +235,151 @@ static NSString *kParamKeyType = @"type"; |
|
@@ -278,135 +235,151 @@ static NSString *kParamKeyType = @"type"; |
278
|
}
|
235
|
}
|
279
|
|
236
|
|
280
|
[performanceAryDic setObject:[YH_EventDataFactory getDataType:type] forKey:kParamKeyType];
|
237
|
[performanceAryDic setObject:[YH_EventDataFactory getDataType:type] forKey:kParamKeyType];
|
281
|
- [performanceAryDic setObject:[YH_EventDataFactory getDeviceInfo:self.performanceAppInfo] forKey:kParamKeyDevice];
|
238
|
+ [performanceAryDic setObject:[YH_EventDataFactory getDeviceInfo:self.appInfo] forKey:kParamKeyDevice];
|
282
|
|
239
|
|
283
|
return performanceAryDic;
|
240
|
return performanceAryDic;
|
284
|
}
|
241
|
}
|
285
|
|
242
|
|
286
|
--(NSString *)getPointName:(YHEventReportPointName)pointName{
|
|
|
287
|
- NSString *str = @"";
|
|
|
288
|
- switch (pointName) {
|
|
|
289
|
- case YHPN_VIEWCONTROLLER:
|
|
|
290
|
- str = @"PAGE";
|
|
|
291
|
- break;
|
|
|
292
|
- case YHPN_WEBVIEW:
|
|
|
293
|
- str = @"WEBVIEW";
|
|
|
294
|
- break;
|
|
|
295
|
- case YHPN_IMAGEVIEW:
|
|
|
296
|
- str = @"IMAGE";
|
|
|
297
|
- break;
|
|
|
298
|
- case YHPN_BUTTON:
|
|
|
299
|
- str = @"BUTTON";
|
|
|
300
|
- break;
|
|
|
301
|
- case YHPN_GESTURERECOGNIZER:
|
|
|
302
|
- str = @"GESTURERECOGNIZER";
|
|
|
303
|
- break;
|
|
|
304
|
- default:
|
|
|
305
|
- break;
|
|
|
306
|
- }
|
|
|
307
|
-
|
|
|
308
|
- return str;
|
|
|
309
|
-}
|
|
|
310
|
-
|
|
|
311
|
--(NSString *)getDataType:(YHEventReportTrackDataType)type{
|
|
|
312
|
- NSString *str = @"";
|
|
|
313
|
-
|
|
|
314
|
- switch (type) {
|
|
|
315
|
- case YHEventReportTrackDataTypeStart:
|
|
|
316
|
- str = @"start";
|
|
|
317
|
- break;
|
|
|
318
|
- case YHEventReportTrackDataTypeDestory:
|
|
|
319
|
- str = @"destory";
|
|
|
320
|
- break;
|
|
|
321
|
- case YHEventReportTrackDataTypeStop:
|
|
|
322
|
- str = @"stop";
|
|
|
323
|
- break;
|
|
|
324
|
- case YHEventReportTrackDataTypeHeartbeat:
|
|
|
325
|
- str = @"hb";
|
|
|
326
|
- break;
|
|
|
327
|
- case YHEventReportTrackDataTypeNONE:
|
|
|
328
|
- str = @"realTime";
|
|
|
329
|
- break;
|
|
|
330
|
- default:
|
|
|
331
|
- break;
|
|
|
332
|
- }
|
|
|
333
|
-
|
|
|
334
|
- return str;
|
|
|
335
|
-}
|
|
|
336
|
-
|
|
|
337
|
-- (void)refreshPushStatus
|
|
|
338
|
-{
|
|
|
339
|
- if (IOS10) {// system is iOS10
|
|
|
340
|
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
341
|
- [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings) {
|
|
|
342
|
- switch (settings.authorizationStatus) {
|
|
|
343
|
- case UNAuthorizationStatusNotDetermined:
|
|
|
344
|
- self.performanceAppInfo.ps = @"0";
|
|
|
345
|
- break;
|
|
|
346
|
- case UNAuthorizationStatusDenied:
|
|
|
347
|
- self.performanceAppInfo.ps = @"0";
|
|
|
348
|
- break;
|
|
|
349
|
- default:
|
|
|
350
|
- self.performanceAppInfo.ps = @"1";
|
|
|
351
|
- break;
|
|
|
352
|
- }
|
|
|
353
|
- }];
|
|
|
354
|
- } else {//iOS8
|
|
|
355
|
- if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone) {
|
|
|
356
|
- self.performanceAppInfo.ps = @"1";
|
|
|
357
|
- }else {
|
|
|
358
|
- self.performanceAppInfo.ps = @"0";
|
|
|
359
|
- }
|
|
|
360
|
- }
|
243
|
+- (void)refreshAppInfo {
|
|
|
244
|
+ dispatch_async(self.queue, ^{
|
|
|
245
|
+ [self.appInfo update];
|
|
|
246
|
+ });
|
361
|
}
|
247
|
}
|
362
|
|
248
|
|
363
|
#pragma mark - NSNotification
|
249
|
#pragma mark - NSNotification
|
364
|
- (void)handleMemoryWarning
|
250
|
- (void)handleMemoryWarning
|
365
|
{
|
251
|
{
|
366
|
- if (self.mode == YHEventReportStrategyInterval) {
|
|
|
367
|
- @synchronized (self.performanceCacheArray) {
|
|
|
368
|
- [self.performanceCacheArray removeAllObjects];
|
252
|
+ dispatch_async(self.queue, ^{
|
|
|
253
|
+ if (self.mode == YHEventReportStrategyInterval) {
|
|
|
254
|
+ //todo save to disk
|
|
|
255
|
+ [self.infoCacheArray removeAllObjects];
|
369
|
}
|
256
|
}
|
370
|
- }
|
257
|
+ });
|
371
|
}
|
258
|
}
|
372
|
- (void)handleDidFinishLaunch
|
259
|
- (void)handleDidFinishLaunch
|
373
|
{
|
260
|
{
|
374
|
- if (self.mode == YHEventReportStrategyInterval) {
|
|
|
375
|
- [self uploadPerformanceDataWithType:YHEventReportTrackDataTypeStart];
|
|
|
376
|
- }
|
261
|
+ dispatch_async(self.queue, ^{
|
|
|
262
|
+ if (self.mode == YHEventReportStrategyInterval) {
|
|
|
263
|
+ [self loadDiskCachedEventInfoToMemArray:self.infoCacheArray];
|
|
|
264
|
+ [self clearDiskCache];
|
|
|
265
|
+ [self uploadEventAndCustomInfo:self.infoCacheArray type:YHEventReportTrackDataTypeStart completion:^(BOOL isSuccess) {
|
|
|
266
|
+ if (isSuccess) {
|
|
|
267
|
+ dispatch_async(self.queue, ^{
|
|
|
268
|
+ [self.infoCacheArray removeAllObjects];
|
|
|
269
|
+ });
|
|
|
270
|
+ }
|
|
|
271
|
+ }];
|
|
|
272
|
+ }
|
|
|
273
|
+ });
|
377
|
}
|
274
|
}
|
378
|
|
275
|
|
379
|
- (void)handleTerminate
|
276
|
- (void)handleTerminate
|
380
|
{
|
277
|
{
|
381
|
- if (self.mode == YHEventReportStrategyInterval) {
|
|
|
382
|
- [self uploadPerformanceDataWithType:YHEventReportTrackDataTypeDestory];
|
|
|
383
|
- }
|
278
|
+ dispatch_sync(self.queue, ^{// block until send over
|
|
|
279
|
+ if (self.mode == YHEventReportStrategyInterval) {
|
|
|
280
|
+ NSArray *array = [self.infoCacheArray copy];
|
|
|
281
|
+ [self.infoCacheArray removeAllObjects];
|
|
|
282
|
+ [self saveToDiskOfInfo:array];
|
|
|
283
|
+ [self uploadEventAndCustomInfo:array type:YHEventReportTrackDataTypeDestory completion:^(BOOL isSuccess) {
|
|
|
284
|
+ if (isSuccess) {
|
|
|
285
|
+ [self clearDiskCache];
|
|
|
286
|
+ }
|
|
|
287
|
+ }];
|
|
|
288
|
+ }
|
|
|
289
|
+ });
|
384
|
}
|
290
|
}
|
385
|
|
291
|
|
386
|
- (void)handleApplicationBackgrounding
|
292
|
- (void)handleApplicationBackgrounding
|
387
|
{
|
293
|
{
|
388
|
- [self.performanceAppInfo resetSessionID];
|
|
|
389
|
- if (self.mode == YHEventReportStrategyInterval) {
|
|
|
390
|
- [self uploadPerformanceDataWithType:YHEventReportTrackDataTypeStop];
|
|
|
391
|
- }
|
294
|
+ dispatch_async(self.queue, ^{
|
|
|
295
|
+ [self.appInfo resetSessionID];
|
|
|
296
|
+ if (self.mode == YHEventReportStrategyInterval) {
|
|
|
297
|
+ NSArray *array = [self.infoCacheArray copy];
|
|
|
298
|
+ [self.infoCacheArray removeAllObjects];
|
|
|
299
|
+ [self saveToDiskOfInfo:array];
|
|
|
300
|
+ [self uploadEventAndCustomInfo:array type:YHEventReportTrackDataTypeStop completion:^(BOOL isSuccess) {
|
|
|
301
|
+ if (isSuccess) {
|
|
|
302
|
+ [self clearDiskCache];
|
|
|
303
|
+ }
|
|
|
304
|
+ }];
|
|
|
305
|
+ }
|
|
|
306
|
+ });
|
|
|
307
|
+}
|
|
|
308
|
+
|
|
|
309
|
+- (void)handleApplicationForerounding {
|
|
|
310
|
+ dispatch_async(self.queue, ^{
|
|
|
311
|
+ [self loadDiskCachedEventInfoToMemArray:self.infoCacheArray];
|
|
|
312
|
+ [self clearDiskCache];
|
|
|
313
|
+ });
|
|
|
314
|
+}
|
|
|
315
|
+
|
|
|
316
|
+- (void)networkStateChange:(NSNotification *)note {
|
|
|
317
|
+ dispatch_async(self.queue, ^{
|
|
|
318
|
+ [self.appInfo updateNetStatusWithReachability:self.intnetReachability];
|
|
|
319
|
+ });
|
392
|
}
|
320
|
}
|
393
|
|
321
|
|
394
|
#pragma mark - timer
|
322
|
#pragma mark - timer
|
395
|
-- (void)timerAction
|
|
|
396
|
-{
|
|
|
397
|
- [self uploadPerformanceDataWithType:YHEventReportTrackDataTypeHeartbeat];
|
323
|
+
|
|
|
324
|
+- (void)startTimer {
|
|
|
325
|
+ if (!_timer) {
|
|
|
326
|
+ weakify(self);
|
|
|
327
|
+ _timer = yh_gcdTimer(_queue, _timeInterval, ^{
|
|
|
328
|
+ strongify(self);
|
|
|
329
|
+ [self timerAction];
|
|
|
330
|
+ });
|
|
|
331
|
+ }
|
|
|
332
|
+}
|
|
|
333
|
+
|
|
|
334
|
+- (void)cancelTimer {
|
|
|
335
|
+ if (_timer) {
|
|
|
336
|
+ dispatch_cancel(_timer);
|
|
|
337
|
+ _timer = nil;
|
|
|
338
|
+ }
|
|
|
339
|
+}
|
|
|
340
|
+
|
|
|
341
|
+- (void)timerAction {
|
|
|
342
|
+ if (!self.infoCacheArray.count) {
|
|
|
343
|
+ return;
|
|
|
344
|
+ }
|
|
|
345
|
+ [self uploadEventAndCustomInfo:self.infoCacheArray type:YHEventReportTrackDataTypeHeartbeat completion:^(BOOL isSuccess) {
|
|
|
346
|
+ if (isSuccess) {
|
|
|
347
|
+ dispatch_async(self.queue, ^{
|
|
|
348
|
+ [self.infoCacheArray removeAllObjects];
|
|
|
349
|
+ });
|
|
|
350
|
+ }
|
|
|
351
|
+ }];
|
398
|
}
|
352
|
}
|
399
|
|
353
|
|
400
|
#pragma mark - upload performance data
|
354
|
#pragma mark - upload performance data
|
401
|
--(void)uploadPerformanceDataWithType:(YHEventReportTrackDataType)type{
|
|
|
402
|
- @synchronized (self.performanceCacheArray) {
|
|
|
403
|
- [self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:self.performanceCacheArray type:type] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
|
|
|
404
|
- }];
|
355
|
+-(void)uploadEventAndCustomInfo:(NSArray *)infoCacheArray type:(YHEventReportTrackDataType)type completion:(void(^)(BOOL isSuccess))completion {
|
|
|
356
|
+ [self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:infoCacheArray type:type] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
|
|
|
357
|
+ BLOCK_EXEC(completion, isSuc);
|
|
|
358
|
+ }];
|
|
|
359
|
+}
|
|
|
360
|
+
|
|
|
361
|
+- (void)saveToDiskOfInfo:(NSArray *)infoArray {
|
|
|
362
|
+ [infoArray writeToFile:[self cachePath] atomically:YES];
|
|
|
363
|
+}
|
|
|
364
|
+
|
|
|
365
|
+- (void)loadDiskCachedEventInfoToMemArray:(NSMutableArray *)memArray {
|
|
|
366
|
+ if (![[NSFileManager defaultManager] fileExistsAtPath:[self cachePath]]) {
|
|
|
367
|
+ return;
|
405
|
}
|
368
|
}
|
406
|
-
|
|
|
407
|
- @synchronized (self.performanceCacheArray) {
|
|
|
408
|
- [self.performanceCacheArray removeAllObjects];
|
369
|
+ NSArray *array = [NSArray arrayWithContentsOfFile:[self cachePath]];
|
|
|
370
|
+ if (array.count) {
|
|
|
371
|
+ [memArray addObjectsFromArray:array];
|
409
|
}
|
372
|
}
|
410
|
}
|
373
|
}
|
411
|
|
374
|
|
|
|
375
|
+- (void)clearDiskCache {
|
|
|
376
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:[self cachePath]]) {
|
|
|
377
|
+ [[NSFileManager defaultManager] removeItemAtPath:[self cachePath] error:nil];
|
|
|
378
|
+ }
|
|
|
379
|
+}
|
|
|
380
|
+
|
|
|
381
|
+- (NSString *)cachePath {
|
|
|
382
|
+ return [NSTemporaryDirectory() stringByAppendingPathComponent:@"event.cache"];
|
|
|
383
|
+}
|
|
|
384
|
+
|
412
|
@end |
385
|
@end |