AppDelegate.swift 5.58 KB
//
//  AppDelegate.swift
//  metaCode
//
//  Created by iOS on 2023/5/30.
//

import UIKit
import CNLiveRequestBastKit
import IQKeyboardManagerSwift
import CNLiveShareToolKit
//import RangersAPM
import CNLivePayCostModule

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Override point for customization after application launch.
        //tencentAppId  wxAppId
        CNLiveShareManager.registeredShareView(whenDidFinishLaunch: universalLinkURL, appId: APPId, tencentAppId: tencentAppId, wxAppId: wxAppId, wxSecret: "", weiBoAppId: "")
        
        CNLiveNetworking.networkStatus { status in
            
            if(status == .notReachable){
                NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationNotReachable, object: nil)
            }
            if(status == .unknown){
                NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationUnknown, object: nil)
            }
            if status == .reachableViaWWAN {
                NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWWAN, object: nil)
            }
            if status == .reachableViaWiFi {
                NotificationCenter.default.post(name: Notification.Name.NetworkStatus.CNLiveNetworkStatusNotificationReachableViaWiFi, object: nil)
            }
        }
        
        //设置APP环境
        CNLiveMCEnvironmentManager.shared.setupEnvironment(environment: .production)
        
        window = UIWindow.init(frame: UIScreen.main.bounds)
        window?.backgroundColor = KVCBackgroupColor
        let is_login = UserDefaults.standard.bool(forKey: "is_login")
        window?.rootViewController = is_login ? CNLiveBaseTabBarViewController.init() : CNLiveLoginViewController.init()
        window?.makeKeyAndVisible()
        
        ///设置APM监控SDK
//        let apmConfig = RangersAPMConfig.init(appID: "591048", appToken: "8dcc7f8b0a3a4aee8ef698311ef89a62")
//        apmConfig.channel = "App Store"
//        apmConfig.deviceIDSource = .fromAPMService
//        apmConfig.defaultMonitors = .apmCrashMonitorSwitch
//        RangersAPM.setUserID(is_login ? UserInfoManager.shared.userInfo.uid : "userID")
//        RangersAPM.allowDebugLog { log in
//            print("APMPlus : %@",log)
//        }
//        RangersAPM.start(with: apmConfig)

        
        AppDelegate_configRequestManager()
        AppDelegate_configIQKeyboardManager()
        
        CNLivePayCostModule.finishLaunchingWithPayPluginSettings(withWWXAppId: "wx82209bed331a549b", hostURL: "https://metacode.cnlive.com")
        
        //认证-下滑原生页数据库
        let databasePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        let filePath = "\(databasePath)/CNLiveDownSlideModelDataBase.db"
        let databaseManager = DatabaseManager(filePath: filePath)
        databaseManager.createTable()
        
        if databaseManager.hasDataInTable(){
            databaseManager.updateIsGetPage(isGetPage: 1)
        }else{
            print("noData")
        }
        return true
    }
    
    // MARK: - 键盘处理
    func AppDelegate_configIQKeyboardManager() {
        IQKeyboardManager.shared.enable = true
        IQKeyboardManager.shared.enableAutoToolbar = true //工具条
        IQKeyboardManager.shared.shouldResignOnTouchOutside = true //点击背景收回键盘
        IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "完成"
        //        IQKeyboardManager.shared.preventShowingBottomBlankSpace = true
        //        IQKeyboardManager.shared.preventShowingBottomBlankSpace = false
        IQKeyboardManager.shared.toolbarTintColor = .lightGray
        IQKeyboardManager.shared.keyboardDistanceFromTextField = 5.0
    }
    
    // MARK: - 网络请求通用参数
    func AppDelegate_configRequestManager() {
        let kAppBundleID = Bundle.main.bundleIdentifier ?? ""
        let uuid : String = UIDevice.current.identifierForVendor?.uuidString.replacingOccurrences(of: "-", with: "") ?? ""
        let ver : String = Bundle.main.infoDictionary?["CFBundleVersion"] as! String
        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"]
        CNLiveNetworking.setupDefaultParam(p)

        let shop_dic : Dictionary = ["Phone-Model":"iPhone","Uid":UserInfoManager.shared.userInfo.uid ,"CFBundleShortVersionString":ver,"Shop-Version":"0.6.2"]
        CNLiveNetworking.setupDSShopParam(shop_dic)
        CNLiveNetworking.setRequestTimeoutInterval(20)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.setupSignKey(APPKey)
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setResponseSerializerType(.JSON)
        CNLiveNetworking.setupBaseURL(APPLoginHost)
    }
    
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        CNLiveShareManager.handleOpenUniversalLink(userActivity)
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        CNLiveShareManager.handleOpen(url)
        return true
    }
}