...
|
...
|
@@ -7,6 +7,7 @@ |
|
|
//
|
|
|
|
|
|
#import "YH_VideoFlowMonitor.h"
|
|
|
#import "YHEventReport.h"
|
|
|
#import <mach/mach.h>
|
|
|
#include <ifaddrs.h>
|
|
|
#include <net/if.h>
|
...
|
...
|
@@ -24,15 +25,6 @@ |
|
|
|
|
|
@implementation YH_VideoFlowMonitor
|
|
|
|
|
|
+ (YH_VideoFlowMonitor *)sharedInstance {
|
|
|
static YH_VideoFlowMonitor *sharedInstance = nil;
|
|
|
static dispatch_once_t onceToken;
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
sharedInstance = [[YH_VideoFlowMonitor alloc] init];
|
|
|
});
|
|
|
return sharedInstance;
|
|
|
}
|
|
|
|
|
|
- (instancetype)init {
|
|
|
if ([super init]) {
|
|
|
if (self) {
|
...
|
...
|
@@ -40,6 +32,9 @@ |
|
|
_finalValue = 0;
|
|
|
_backValue = 0;
|
|
|
_foreValue = 0;
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackGround) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -48,22 +43,29 @@ |
|
|
|
|
|
- (void)startFlowMonitor {
|
|
|
_originValue = [self transferNetFlow];
|
|
|
|
|
|
}
|
|
|
|
|
|
- (void)stopFlowMonitor {
|
|
|
_finalValue = [self transferNetFlow];
|
|
|
|
|
|
int64_t lastValue = _finalValue - _originValue - (_foreValue - _backValue);
|
|
|
NSLog(@"lastValue:%lld", lastValue);
|
|
|
NSString *trafficBytes = [NSString stringWithFormat:@"%lld", lastValue];
|
|
|
NSString *videoUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"UFO_VideoUrl"];
|
|
|
NSString *fromPage = [[NSUserDefaults standardUserDefaults] objectForKey:@"UFO_FromPage"];
|
|
|
|
|
|
NSDictionary *trafficDict = @{ @"url" : videoUrl?videoUrl:@"",
|
|
|
@"traffic" : trafficBytes?trafficBytes:@"",
|
|
|
@"fromPage" : fromPage?fromPage:@""
|
|
|
};
|
|
|
[[YHEventReport sharedInstance] reportWithPointType:YHPT_UFOBUSINESS pointName:YHPN_BUSINESS_UFO_VIDEO_TRAFFIC parameters:trafficDict];
|
|
|
}
|
|
|
|
|
|
- (void)enterBackgroundMonitor {
|
|
|
_backValue = [self transferNetFlow];
|
|
|
- (void)appBecomeActive {
|
|
|
_foreValue = [self transferNetFlow];
|
|
|
}
|
|
|
|
|
|
- (void)enterForegroundMonitor {
|
|
|
_foreValue = [self transferNetFlow];
|
|
|
- (void)appDidEnterBackGround {
|
|
|
_backValue = [self transferNetFlow];
|
|
|
}
|
|
|
|
|
|
- (int64_t)transferNetFlow {
|
...
|
...
|
@@ -111,6 +113,5 @@ |
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
...
|
...
|
|