AppDelegate.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // AppDelegate.swift
  3. // AIPlayRingtones
  4. //
  5. // Created by 100Years on 2025/5/15.
  6. //
  7. import UIKit
  8. @main
  9. class AppDelegate: UIResponder, UIApplicationDelegate {
  10. var window: UIWindow?
  11. var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = .invalid
  12. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  13. window = UIWindow(frame: UIScreen.main.bounds)
  14. window?.backgroundColor = UIColor.black
  15. window?.makeKeyAndVisible()
  16. initPlatform()
  17. goToLoadVC()
  18. return true
  19. }
  20. func goToLoadVC() {
  21. let launchVC = ASLaunchVC()
  22. launchVC.dismissHandler = { [weak self] in
  23. guard let self = self else { return }
  24. JudgmentSkipPage()
  25. }
  26. window?.rootViewController = launchVC
  27. }
  28. func goToTab() {
  29. window?.rootViewController = CustomTabBarController()
  30. }
  31. func JudgmentSkipPage() {
  32. // if AppDelegate.isFirstInstallApp() {
  33. // let bootPageVC = TSBootPageVC { [weak self] in
  34. // guard let self = self else { return }
  35. // UserDefaults.standard.set("1", forKey: "isFirstInstallApp")
  36. // UserDefaults.standard.synchronize()
  37. // goToTab()
  38. // }
  39. // let navi = TSBaseNavigationC(rootViewController: bootPageVC)
  40. // window?.rootViewController = navi
  41. // } else {
  42. goToTab()
  43. // }
  44. }
  45. func initPlatform() {
  46. DispatchQueue.main.async {//先提前调用,启动下数据库.
  47. debugPrint("ASRMShared.ringDBHistory.istModels.count = \(ASRMShared.ringDBHistory.listModels.count)")
  48. }
  49. }
  50. }
  51. extension AppDelegate {
  52. func applicationDidEnterBackground(_ application: UIApplication) {
  53. beginBackgroundTask()
  54. }
  55. func beginBackgroundTask() {
  56. backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask { [weak self] in
  57. self?.endBackgroundTask()
  58. }
  59. }
  60. func endBackgroundTask() {
  61. if backgroundTaskIdentifier != .invalid {
  62. UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
  63. backgroundTaskIdentifier = .invalid
  64. }
  65. }
  66. func applicationWillEnterForeground(_ application: UIApplication) {
  67. }
  68. func applicationWillTerminate(_ application: UIApplication) {
  69. // 当应用即将被终止时,这里也可以添加数据保存逻辑,但系统留给的时间很有限
  70. }
  71. }
  72. extension AppDelegate {
  73. static func isFirstInstallApp() -> Bool {
  74. return UserDefaults.standard.string(forKey: "isFirstInstallApp") == nil
  75. }
  76. }