Authored by 张文文

添加上报字段和内容

@@ -144,6 +144,7 @@ typedef NS_ENUM(NSInteger, YHEventReportPointName) { @@ -144,6 +144,7 @@ typedef NS_ENUM(NSInteger, YHEventReportPointName) {
144 144
145 YHPN_BUSINESS_UFO_SELL,//BUSINESS_UFO_SELL 145 YHPN_BUSINESS_UFO_SELL,//BUSINESS_UFO_SELL
146 YHPN_BUSINESS_UFO_BUY,//BUSINESS_UFO_BUY 146 YHPN_BUSINESS_UFO_BUY,//BUSINESS_UFO_BUY
  147 + YHPN_BUSINESS_UFO_VIDEO_TRAFFIC,//BUSINESS_UFO_VIDEO_TRAFFIC
147 148
148 }; 149 };
149 150
@@ -171,7 +172,8 @@ typedef NS_ENUM(NSInteger, YHPointType) { @@ -171,7 +172,8 @@ typedef NS_ENUM(NSInteger, YHPointType) {
171 YHPT_BUSINESS, 172 YHPT_BUSINESS,
172 YHPT_PERFORMANCE, 173 YHPT_PERFORMANCE,
173 YHPT_AD, 174 YHPT_AD,
174 - YHPT_APPTARGET 175 + YHPT_APPTARGET,
  176 + YHPT_UFOBUSINESS,
175 }; 177 };
176 178
177 #define YHEventReportDebugModeEnableKey @"YHEventReportDebugModeEnableKey" 179 #define YHEventReportDebugModeEnableKey @"YHEventReportDebugModeEnableKey"
@@ -289,6 +289,9 @@ @@ -289,6 +289,9 @@
289 case YHPN_APPFPS: 289 case YHPN_APPFPS:
290 str = @"FPS"; 290 str = @"FPS";
291 break; 291 break;
  292 + case YHPN_BUSINESS_UFO_VIDEO_TRAFFIC:
  293 + str = @"UFO_BUSINESS_VIDEO_TRAFFIC";
  294 + break;
292 default: 295 default:
293 break; 296 break;
294 } 297 }
@@ -329,6 +332,9 @@ @@ -329,6 +332,9 @@
329 case YHPT_APPTARGET: 332 case YHPT_APPTARGET:
330 str = @"APPTARGET"; 333 str = @"APPTARGET";
331 break; 334 break;
  335 + case YHPT_UFOBUSINESS:
  336 + str = @"UFO_BUSINESS";
  337 + break;
332 default: 338 default:
333 break; 339 break;
334 } 340 }
@@ -12,12 +12,8 @@ NS_ASSUME_NONNULL_BEGIN @@ -12,12 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
12 12
13 @interface YH_VideoFlowMonitor : NSObject 13 @interface YH_VideoFlowMonitor : NSObject
14 14
15 -+ (YH_VideoFlowMonitor *)sharedInstance;  
16 -  
17 - (void)startFlowMonitor; 15 - (void)startFlowMonitor;
18 - (void)stopFlowMonitor; 16 - (void)stopFlowMonitor;
19 -- (void)enterForegroundMonitor;  
20 -- (void)enterBackgroundMonitor;  
21 17
22 @end 18 @end
23 19
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 // 7 //
8 8
9 #import "YH_VideoFlowMonitor.h" 9 #import "YH_VideoFlowMonitor.h"
  10 +#import "YHEventReport.h"
10 #import <mach/mach.h> 11 #import <mach/mach.h>
11 #include <ifaddrs.h> 12 #include <ifaddrs.h>
12 #include <net/if.h> 13 #include <net/if.h>
@@ -24,15 +25,6 @@ @@ -24,15 +25,6 @@
24 25
25 @implementation YH_VideoFlowMonitor 26 @implementation YH_VideoFlowMonitor
26 27
27 -+ (YH_VideoFlowMonitor *)sharedInstance {  
28 - static YH_VideoFlowMonitor *sharedInstance = nil;  
29 - static dispatch_once_t onceToken;  
30 - dispatch_once(&onceToken, ^{  
31 - sharedInstance = [[YH_VideoFlowMonitor alloc] init];  
32 - });  
33 - return sharedInstance;  
34 -}  
35 -  
36 - (instancetype)init { 28 - (instancetype)init {
37 if ([super init]) { 29 if ([super init]) {
38 if (self) { 30 if (self) {
@@ -40,6 +32,9 @@ @@ -40,6 +32,9 @@
40 _finalValue = 0; 32 _finalValue = 0;
41 _backValue = 0; 33 _backValue = 0;
42 _foreValue = 0; 34 _foreValue = 0;
  35 +
  36 + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
  37 + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackGround) name:UIApplicationDidEnterBackgroundNotification object:nil];
43 } 38 }
44 } 39 }
45 40
@@ -48,22 +43,29 @@ @@ -48,22 +43,29 @@
48 43
49 - (void)startFlowMonitor { 44 - (void)startFlowMonitor {
50 _originValue = [self transferNetFlow]; 45 _originValue = [self transferNetFlow];
51 -  
52 } 46 }
53 47
54 - (void)stopFlowMonitor { 48 - (void)stopFlowMonitor {
55 _finalValue = [self transferNetFlow]; 49 _finalValue = [self transferNetFlow];
56 50
57 int64_t lastValue = _finalValue - _originValue - (_foreValue - _backValue); 51 int64_t lastValue = _finalValue - _originValue - (_foreValue - _backValue);
58 - NSLog(@"lastValue:%lld", lastValue); 52 + NSString *trafficBytes = [NSString stringWithFormat:@"%lld", lastValue];
  53 + NSString *videoUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"UFO_VideoUrl"];
  54 + NSString *fromPage = [[NSUserDefaults standardUserDefaults] objectForKey:@"UFO_FromPage"];
  55 +
  56 + NSDictionary *trafficDict = @{ @"url" : videoUrl?videoUrl:@"",
  57 + @"traffic" : trafficBytes?trafficBytes:@"",
  58 + @"fromPage" : fromPage?fromPage:@""
  59 + };
  60 + [[YHEventReport sharedInstance] reportWithPointType:YHPT_UFOBUSINESS pointName:YHPN_BUSINESS_UFO_VIDEO_TRAFFIC parameters:trafficDict];
59 } 61 }
60 62
61 -- (void)enterBackgroundMonitor {  
62 - _backValue = [self transferNetFlow]; 63 +- (void)appBecomeActive {
  64 + _foreValue = [self transferNetFlow];
63 } 65 }
64 66
65 -- (void)enterForegroundMonitor {  
66 - _foreValue = [self transferNetFlow]; 67 +- (void)appDidEnterBackGround {
  68 + _backValue = [self transferNetFlow];
67 } 69 }
68 70
69 - (int64_t)transferNetFlow { 71 - (int64_t)transferNetFlow {
@@ -111,6 +113,5 @@ @@ -111,6 +113,5 @@
111 } 113 }
112 114
113 115
114 -  
115 @end 116 @end
116 117