|
@@ -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
|
|