CNLivePlayerManager.m
2.27 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
//
// CNLivePlayerManager.m
// CNLivePlayer_Example
//
// Created by CNLive-zxw on 2019/7/26.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
#import "CNLivePlayerManager.h"
#import <libksygpulive/KSYGPUStreamerKit.h>
#import "CNLivePlayerConst.h"
@interface CNLivePlayerManager()
/**
* 应用ID(只读)
*/
@property (nonatomic, copy, readwrite) NSString *appId;
/**
* 应用KEY(只读)
*/
@property (nonatomic, copy, readwrite) NSString *appKey;
/**
* 是否是测试环境
*/
@property (nonatomic, assign, readwrite) BOOL isTestEnvironment;
@end
@implementation CNLivePlayerManager
static CNLivePlayerManager * _instance = nil;
+ (CNLivePlayerManager *)manager {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc] init];
//清除播放器鉴权缓存
[CNLivePlayerManager clearAuthentication];
});
return _instance;
}
+ (void)setAppId:(NSString *)appId appKey:(NSString *)appKey {
[CNLivePlayerManager setAppId:appId appKey:appKey isTestEnvironment:NO];
}
+ (void)setAppId:(NSString *)appId appKey:(NSString *)appKey isTestEnvironment:(BOOL)isTestEnvironment{
[[CNLivePlayerManager manager] setAppId:appId appKey:appKey isTestEnvironment:isTestEnvironment];
}
#pragma mark - 私有方法
- (void)setAppId:(NSString *)appId appKey:(NSString *)appKey {
[self setAppId:appId appKey:appKey isTestEnvironment:NO];
}
- (void)setAppId:(NSString *)appId appKey:(NSString *)appKey isTestEnvironment:(BOOL)isTestEnvironment {
self.appId = appId ? [NSString stringWithFormat:@"%@",appId] : @"";
self.appKey = appKey ? [NSString stringWithFormat:@"%@",appKey] : @"";
self.isTestEnvironment = isTestEnvironment;
}
+ (NSString *)getVersion {
KSYGPUStreamerKit *kit = [[KSYGPUStreamerKit alloc] init];
NSString *str = [[[kit.streamerBase getKSYVersion] componentsSeparatedByString:@"-"] lastObject];
return [NSString stringWithFormat:@"%@_%@", PlayerSDKVersion,str];
}
+ (void)clearAuthentication {
NSDictionary *authenticationDic = [[NSUserDefaults standardUserDefaults] objectForKey:kCNLivePlayerSDKAuthentication];
if (authenticationDic) {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kCNLivePlayerSDKAuthentication];
}
}
@end