AppDelegate.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // AppDelegate.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/10.
  6. //
  7. import UIKit
  8. import AMapFoundationKit
  9. import IQKeyboardManagerSwift
  10. @main
  11. class AppDelegate: UIResponder, UIApplicationDelegate {
  12. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  13. // Override point for customization after application launch.
  14. Thread.sleep(forTimeInterval: 1)
  15. IQKeyboardManager.shared.enable = true
  16. AMapServices.shared().apiKey = QSLConfig.MapKey
  17. //启动埋点
  18. managerAppOnlyLaunch()
  19. return true
  20. }
  21. // MARK: UISceneSession Lifecycle
  22. func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  23. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  24. }
  25. func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  26. }
  27. //管理app启动埋点
  28. func managerAppOnlyLaunch() {
  29. guard UserDefaults.standard.string(forKey: "MANAGER_APP_ONLY_LAUNCH") != nil else {
  30. UserDefaults.standard.set("YES", forKey: "MANAGER_APP_ONLY_LAUNCH")
  31. UserDefaults.standard.synchronize()
  32. //只有app第一次启动才会埋点
  33. gravityInstance?.track(QSLGravityConst.app_launch, properties: ["id": 02001])
  34. return
  35. }
  36. }
  37. // 当 App 即将终止(退出)时调用
  38. func applicationWillTerminate(_ application: UIApplication) {
  39. print("App 即将退出")
  40. // 仅在 App 被用户主动退出或系统正常终止时触发(强制杀死进程时可能不调用)
  41. // 可在此做最后的数据保存(操作需快速完成,系统可能限制时间)
  42. ///埋点app退出
  43. gravityInstance?.track(QSLGravityConst.app_exit, properties: ["id": 02002])
  44. }
  45. }