AppDelegate.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // AppDelegate.swift
  3. // AIEmoji
  4. //
  5. // Created by 100Years on 2025/1/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.white
  15. window?.makeKeyAndVisible()
  16. initPlatform()
  17. goToLoadVC()
  18. return true
  19. }
  20. func goToLoadVC() {
  21. let launchVC = TSLaunchVC()
  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 = TSTabBarController()
  30. }
  31. func JudgmentSkipPage() {
  32. //去掉引导页
  33. // if UserDefaults.standard.string(forKey: "isFirstInstallApp") == nil {
  34. // window?.rootViewController = TSBootPageVC { [weak self] in
  35. // guard let self = self else { return }
  36. // UserDefaults.standard.set("1", forKey: "isFirstInstallApp")
  37. // UserDefaults.standard.synchronize()
  38. // goToTab()
  39. // }
  40. // }else{
  41. goToTab()
  42. // }
  43. }
  44. func initPlatform() {
  45. TSColorConfigShared.naviMianTextColor = .white
  46. }
  47. }
  48. extension AppDelegate {
  49. func applicationWillTerminate(_ application: UIApplication) {
  50. // 当应用即将被终止时,这里也可以添加数据保存逻辑,但系统留给的时间很有限
  51. NotificationCenter.default.post(name: .kApplicationWillTerminate, object: nil)
  52. }
  53. func applicationDidEnterBackground(_ application: UIApplication) {
  54. beginBackgroundTask()
  55. }
  56. func beginBackgroundTask() {
  57. backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask { [weak self] in
  58. self?.endBackgroundTask()
  59. }
  60. }
  61. func endBackgroundTask() {
  62. if backgroundTaskIdentifier != .invalid {
  63. UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
  64. backgroundTaskIdentifier = .invalid
  65. }
  66. }
  67. }