CNLiveUserManager.m
4.58 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
//
// CNLiveUserManager.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/18.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "CNLiveUserManager.h"
#import "CNLiveUserSystemTools.h"
#import "Common.h"
#define formalStatUrl @"http://app.sta.cnlive.com/app.js"
@interface CNLiveUserManager ()
{
NSDate *_startDate;
}
@end
@implementation CNLiveUserManager
+ (CNLiveUserManager *)manager
{
static id instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
- (void)addObserver
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnterBackground) name:UIApplicationWillResignActiveNotification object:nil];
}
- (void)startUserStat
{
[CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) {
_startDate = netDate;
NSString *stamp = realTime;
stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *baseUrl = formalStatUrl;
NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=apple&spid=&appid=%@&version=1005_%@&eventid=1300&uri=&sid=&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion, StatAppVersion];
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil];
}];
}
- (void)endUserStat
{
[CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) {
NSString *stamp = realTime;
stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *endDate = [NSString stringWithFormat:@"%.3f",[netDate timeIntervalSinceDate:_startDate]];
endDate = [endDate stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *baseUrl = formalStatUrl;
NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=apple&spid=&appid=%@&version=1005_%@&eventid=1311&uri=%@&sid=&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion,endDate,StatAppVersion];
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil];
}];
}
- (void)wjjStartUserStat
{
[CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) {
_startDate = netDate;
NSString *stamp = realTime;
stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *baseUrl = formalStatUrl;
NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=apple&spid=&appid=%@&version=1005_%@&eventid=1320&uri=&sid=%@&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion, [CNLiveUserManager manager].userId,StatAppVersion];
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil];
}];
}
- (void)wjjEndUserStat
{
[CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) {
NSString *stamp = realTime;
stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *endDate = [NSString stringWithFormat:@"%.3f",[netDate timeIntervalSinceDate:_startDate]];
endDate = [endDate stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *baseUrl = formalStatUrl;
NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=apple&spid=&appid=%@&version=1005_%@&eventid=1321&uri=%@&sid=%@&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion,endDate,[CNLiveUserManager manager].userId,StatAppVersion];
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil];
}];
}
- (void)applicationBecomeActive
{
[self startUserStat];
if ([CNLiveUserManager manager].userId)
{
[self wjjStartUserStat];
}
}
- (void)applicationEnterBackground
{
[self endUserStat];
if ([CNLiveUserManager manager].userId)
{
[self wjjEndUserStat];
}
}
@end