CNLiveEnvironment.swift
3.09 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
//
// CNLiveEnvironment.swift
// metaCode
//
// Created by daojian on 2023/6/15.
//
import Foundation
///当前应用的APPID
let APPId: String = CNLiveEnvironmentManager.shared.appId
///当前应用的APPKey
let APPKey: String = CNLiveEnvironmentManager.shared.appKey
///当前应用的网络请求域名
let APPBaseUrl: String! = CNLiveEnvironmentManager.shared.baseUrl
///当前应用的Secret
let APPSecret: String = CNLiveEnvironmentManager.shared.appSecret
///当前APP的环境
let APPCurrentEnvironment: CNLiveEnvironment = CNLiveEnvironmentManager.shared.currentEnvironment
///是否是开发环境
let IsDevEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .development)
///是否是testFlight 环境
let IsTestFlightEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .testFlight)
///是否是线上环境
let IsProductionEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .production)
///APP 环境类型
enum CNLiveEnvironment {
///开发环境
case development
///testFlight 环境
case testFlight
///线上环境
case production
}
class CNLiveEnvironmentManager: NSObject{
//单例类
static let shared = CNLiveEnvironmentManager()
var appId: String
var appKey: String
var baseUrl: String
var appSecret: String
///当前环境
var currentEnvironment: CNLiveEnvironment
//重新init方法为私有,不让外部调用
private override init() {
self.appId = ""
self.appKey = ""
self.baseUrl = ""
self.appSecret = ""
self.currentEnvironment = .development
}
//重新copy 和 mutableCopy 方法
override func copy() -> Any {
return self
}
override func mutableCopy() -> Any {
return self
}
//配置环境
func setupEnvironment(environment: CNLiveEnvironment){
self.currentEnvironment = environment
switch environment {
case .development:
self.developmentEnvironment()
case .testFlight:
self.testFlightEnvironment()
case .production:
self.productionEnvironment()
}
}
//开发环境配置
func developmentEnvironment(){
self.appId = "802_li40qhp922"
self.appKey = "ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac"
self.appSecret = "3cc9f12db322a3d3656012ef929604cf6d6847471535f9"
self.baseUrl = "https://api.cnlive.com"
}
//testFlight 环境配置
func testFlightEnvironment(){
self.appId = "802_li40qhp922"
self.appKey = "ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac"
self.appSecret = "3cc9f12db322a3d3656012ef929604cf6d6847471535f9"
self.baseUrl = "https://api.cnlive.com"
}
//production 生产环境配置
func productionEnvironment(){
self.appId = "769_li40lrkt53"
self.appKey = "064f392f84dfe7bbe9f1eabeda53ea02044213019b0406"
self.appSecret = "68b5cc42fbdb466d56c2e22b00b1494feec8149f9dd32e"
self.baseUrl = "https://api.cnlive.com"
}
}