CNLiveEnvironment.swift 3.09 KB
//
//  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"
    }
    
}