Commit 611d93029295756524642915e2d25a5417398ef1

Authored by niudaojian
1 parent f89b8f7b

添加APP环境配置

metaCode.xcodeproj/project.pbxproj
... ... @@ -49,6 +49,7 @@
49 49 79F4B11C2A33036E00993C03 /* CNLiveMineInfoAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F4B11B2A33036E00993C03 /* CNLiveMineInfoAlertView.swift */; };
50 50 7C2703302A36CBE30061EC50 /* CNCertificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C27032F2A36CBE30061EC50 /* CNCertificationView.swift */; };
51 51 7C2703332A36CC660061EC50 /* CNLiveGlobalBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C2703322A36CC660061EC50 /* CNLiveGlobalBlock.swift */; };
  52 + 7C2703362A3AFD3A0061EC50 /* CNLiveEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C2703352A3AFD3A0061EC50 /* CNLiveEnvironment.swift */; };
52 53 7C4931292A2D8BA8000E44B4 /* CNLiveBaseTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C4931282A2D8BA8000E44B4 /* CNLiveBaseTabBarViewController.swift */; };
53 54 7C49312D2A2DB9FA000E44B4 /* UITabBar+CNBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C49312C2A2DB9FA000E44B4 /* UITabBar+CNBadge.swift */; };
54 55 7C4931312A2F142F000E44B4 /* CNHomePageBackgroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C4931302A2F142F000E44B4 /* CNHomePageBackgroupView.swift */; };
... ... @@ -138,6 +139,7 @@
138 139 79F4B11B2A33036E00993C03 /* CNLiveMineInfoAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveMineInfoAlertView.swift; sourceTree = "<group>"; };
139 140 7C27032F2A36CBE30061EC50 /* CNCertificationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNCertificationView.swift; sourceTree = "<group>"; };
140 141 7C2703322A36CC660061EC50 /* CNLiveGlobalBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveGlobalBlock.swift; sourceTree = "<group>"; };
  142 + 7C2703352A3AFD3A0061EC50 /* CNLiveEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveEnvironment.swift; sourceTree = "<group>"; };
141 143 7C4931282A2D8BA8000E44B4 /* CNLiveBaseTabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveBaseTabBarViewController.swift; sourceTree = "<group>"; };
142 144 7C49312C2A2DB9FA000E44B4 /* UITabBar+CNBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITabBar+CNBadge.swift"; sourceTree = "<group>"; };
143 145 7C4931302A2F142F000E44B4 /* CNHomePageBackgroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNHomePageBackgroupView.swift; sourceTree = "<group>"; };
... ... @@ -299,6 +301,7 @@
299 301 7963988A2A260B3300D045EB /* Classes */ = {
300 302 isa = PBXGroup;
301 303 children = (
  304 + 7C2703342A3AFD130061EC50 /* Environment */,
302 305 7C2703312A36CC430061EC50 /* GlobalBlock */,
303 306 798A44F32A3077ED00815935 /* CustomView */,
304 307 790D01832A2D89E100C5978D /* Extensions */,
... ... @@ -433,6 +436,14 @@
433 436 path = GlobalBlock;
434 437 sourceTree = "<group>";
435 438 };
  439 + 7C2703342A3AFD130061EC50 /* Environment */ = {
  440 + isa = PBXGroup;
  441 + children = (
  442 + 7C2703352A3AFD3A0061EC50 /* CNLiveEnvironment.swift */,
  443 + );
  444 + path = Environment;
  445 + sourceTree = "<group>";
  446 + };
436 447 7CD675212A26F844008354C1 /* HomePage */ = {
437 448 isa = PBXGroup;
438 449 children = (
... ... @@ -798,6 +809,7 @@
798 809 7C4931382A307BDB000E44B4 /* CNHomePageGuideView.swift in Sources */,
799 810 7CD6753E2A2740B0008354C1 /* CNPayMoneyCodeView.swift in Sources */,
800 811 7CD675402A2740B0008354C1 /* CNCollectMoneyCodeView.swift in Sources */,
  812 + 7C2703362A3AFD3A0061EC50 /* CNLiveEnvironment.swift in Sources */,
801 813 798A44FD2A309EBA00815935 /* CNLiveTypeFeedBackViewController.swift in Sources */,
802 814 7CD6754F2A2840B9008354C1 /* CNMetaCodeHomePageController.swift in Sources */,
803 815 7CD675472A274167008354C1 /* NewPagedFlowView.m in Sources */,
... ...
metaCode/Classes/Environment/CNLiveEnvironment.swift 0 → 100644
  1 +//
  2 +// CNLiveEnvironment.swift
  3 +// metaCode
  4 +//
  5 +// Created by daojian on 2023/6/15.
  6 +//
  7 +
  8 +import Foundation
  9 +
  10 +///当前应用的APPID
  11 +let APPId: String = CNLiveEnvironmentManager.shared.appId
  12 +///当前应用的APPKey
  13 +let APPKey: String = CNLiveEnvironmentManager.shared.appKey
  14 +///当前应用的网络请求域名
  15 +let APPBaseUrl: String! = CNLiveEnvironmentManager.shared.baseUrl
  16 +
  17 +
  18 +///当前APP的环境
  19 +let APPCurrentEnvironment: CNLiveEnvironment = CNLiveEnvironmentManager.shared.currentEnvironment
  20 +
  21 +///是否是开发环境
  22 +let IsDevEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .development)
  23 +///是否是testFlight 环境
  24 +let IsTestFlightEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .testFlight)
  25 +///是否是线上环境
  26 +let IsProductionEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .production)
  27 +
  28 +///环境类型
  29 +enum CNLiveEnvironment {
  30 + ///开发环境
  31 + case development
  32 + ///testFlight 环境
  33 + case testFlight
  34 + ///线上环境
  35 + case production
  36 +
  37 +}
  38 +
  39 +class CNLiveEnvironmentManager: NSObject{
  40 +
  41 + //单例类
  42 + static let shared = CNLiveEnvironmentManager()
  43 +
  44 + var appId: String
  45 + var appKey: String
  46 + var baseUrl: String
  47 +
  48 + ///当前环境
  49 + var currentEnvironment: CNLiveEnvironment
  50 +
  51 + //重新init方法为私有,不让外部调用
  52 + private override init() {
  53 + self.appId = ""
  54 + self.appKey = ""
  55 + self.baseUrl = ""
  56 + self.currentEnvironment = .development
  57 + }
  58 + //重新copy 和 mutableCopy 方法
  59 + override func copy() -> Any {
  60 + return self
  61 + }
  62 +
  63 + override func mutableCopy() -> Any {
  64 + return self
  65 + }
  66 +
  67 + //配置环境
  68 + func setupEnvironment(environment: CNLiveEnvironment){
  69 +
  70 + self.currentEnvironment = environment
  71 +
  72 + switch environment {
  73 + case .development:
  74 + self.developmentEnvironment()
  75 + case .testFlight:
  76 + self.testFlightEnvironment()
  77 + case .production:
  78 + self.productionEnvironment()
  79 + }
  80 + }
  81 +
  82 + //开发环境配置
  83 + func developmentEnvironment(){
  84 + self.appId = "802_li40qhp922"
  85 + self.appKey = "ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac"
  86 + self.baseUrl = "https://api.cnlive.com"
  87 + }
  88 + //testFlight 环境配置
  89 + func testFlightEnvironment(){
  90 + self.appId = "802_li40qhp922"
  91 + self.appKey = "ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac"
  92 + self.baseUrl = "https://api.cnlive.com"
  93 + }
  94 + //production 生产环境配置
  95 + func productionEnvironment(){
  96 + self.appId = "802_li40qhp922"
  97 + self.appKey = "ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac"
  98 + self.baseUrl = "https://api.cnlive.com"
  99 + }
  100 +
  101 +}
... ...
metaCode/Classes/Other/AppDelegate.swift
... ... @@ -19,6 +19,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
19 19  
20 20 // Override point for customization after application launch.
21 21  
  22 + //设置APP环境
  23 + CNLiveEnvironmentManager.shared.setupEnvironment(environment: .development)
  24 +
22 25 window = UIWindow.init(frame: UIScreen.main.bounds)
23 26 window?.backgroundColor = KVCBackgroupColor
24 27 window?.rootViewController = UserInfoManager.shared.is_login ? CNLiveBaseTabBarViewController.init() : CNLiveLoginViewController.init()
... ... @@ -49,13 +52,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
49 52 let kAppBundleID = Bundle.main.bundleIdentifier ?? ""
50 53 let uuid : String = UIDevice.current.identifierForVendor?.uuidString.replacingOccurrences(of: "-", with: "") ?? ""
51 54 let ver : String = Bundle.main.infoDictionary?["CFBundleVersion"] as! String
52   - let p : Dictionary = ["platform_id":kAppBundleID,"uuid":uuid,"plat":"i","ver":ver,"appId":"802_li40qhp922","timestamp":String(NSNumber(floatLiteral: Date().timeIntervalSince1970).intValue),"clientPlat":"i","frmId":"ios"]
  55 + let p : Dictionary = ["platform_id":kAppBundleID,"uuid":uuid,"plat":"i","ver":ver,"appId":APPId,"timestamp":String(NSNumber(floatLiteral: Date().timeIntervalSince1970).intValue),"clientPlat":"i","frmId":"ios"]
53 56 CNLiveNetworking.setupDefaultParam(p)
54 57 CNLiveNetworking.setupShowDataResult(false)
55   - CNLiveNetworking.setupSignKey("ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac")
  58 + CNLiveNetworking.setupSignKey(APPKey)
56 59 CNLiveNetworking.setAllowRequestDefaultArgument(true)
57 60 CNLiveNetworking.setResponseSerializerType(.JSON)
58   - CNLiveNetworking.setupBaseURL("https://api.cnlive.com")
  61 + CNLiveNetworking.setupBaseURL(APPBaseUrl)
59 62 }
60 63  
61 64  
... ...