//
//  AppDelegate.swift
//  SwiftProject
//
//  Created by soldoros on 2024/1/10.
//
/*
 com.peuid.snsdev
 com.nks.vptest
 
 蓝湖 https://moonvy.com/invite/97510620-9c5f-4af2-ab86-982a8ce4e09c
 原型 https://avb2dt3u5c4.feishu.cn/docx/MRRedj0p9ocNa3x6LkycqGyqn0e
 接口 https://apifox.com/apidoc/shared-088c9b06-e12a-490b-9f99-6949fb51dbbb
 串流播放 https://www.finnvoorhees.com/words/reading-and-writing-spatial-video-with-avfoundation
 */

import UIKit
import SVProgressHUD
import Firebase
@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var root:RootManager?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Task {
            FirebaseApp.configure()
        }
        
        SVProgressHUD.setDefaultStyle(.dark)
        
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        self.window?.makeKeyAndVisible()
        self.window?.rootViewController =  RootTabBarController()
        Analytics.logEvent("user_launch", parameters: ["type":"new"])
        
        exceptionLogWithData()
        return true
    }
    
 
    func exceptionLogWithData() {
            CopyCrashHandler.setDefaultHandler()
            let str = CopyCrashHandler.getdataPath()
            let data = NSData.init(contentsOfFile: str)
            if data != nil {
                let crushStr:String? = String.init(data: data! as Data, encoding: String.Encoding.utf8)
                Analytics.logEvent("app_crash", parameters: ["crashInfo":crushStr ?? ""])
            }

        }
    

    //前后台切换--进入前台
    func applicationWillEnterForeground(_ application: UIApplication) {
        print("applicationWillEnterForeground...")
        Analytics.logEvent("user_launch", parameters: ["type":"restart"])
    }

    func applicationWillTerminate(_ application: UIApplication) {
        
    }

}

