AppDelegate.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // AppDelegate.swift
  3. // AIEmoji
  4. //
  5. // Created by 100Years on 2025/1/15.
  6. //
  7. import UIKit
  8. var kAppNewVerison = ""
  9. @main
  10. class AppDelegate: UIResponder, UIApplicationDelegate {
  11. var window: UIWindow?
  12. var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = .invalid
  13. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  14. window = UIWindow(frame: UIScreen.main.bounds)
  15. window?.backgroundColor = UIColor.white
  16. window?.makeKeyAndVisible()
  17. initPlatform()
  18. goToLoadVC()
  19. return true
  20. }
  21. func goToLoadVC() {
  22. let launchVC = TSLaunchVC()
  23. launchVC.dismissHandler = { [weak self] in
  24. guard let self = self else { return }
  25. JudgmentSkipPage()
  26. }
  27. window?.rootViewController = launchVC
  28. }
  29. func goToTab(){
  30. window?.rootViewController = TSTabBarController()
  31. }
  32. func JudgmentSkipPage() {
  33. //去掉引导页
  34. // if UserDefaults.standard.string(forKey: "isFirstInstallApp") == nil {
  35. // window?.rootViewController = TSBootPageVC { [weak self] in
  36. // guard let self = self else { return }
  37. // UserDefaults.standard.set("1", forKey: "isFirstInstallApp")
  38. // UserDefaults.standard.synchronize()
  39. // goToTab()
  40. // }
  41. // }else{
  42. goToTab()
  43. // }
  44. }
  45. func initPlatform() {
  46. TSColorConfigShared.naviMianTextColor = .white
  47. checkAppConfig()
  48. }
  49. }
  50. extension AppDelegate {
  51. func applicationWillTerminate(_ application: UIApplication) {
  52. // 当应用即将被终止时,这里也可以添加数据保存逻辑,但系统留给的时间很有限
  53. NotificationCenter.default.post(name: .kApplicationWillTerminate, object: nil)
  54. }
  55. func applicationDidEnterBackground(_ application: UIApplication) {
  56. beginBackgroundTask()
  57. }
  58. func beginBackgroundTask() {
  59. backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask { [weak self] in
  60. self?.endBackgroundTask()
  61. }
  62. }
  63. func endBackgroundTask() {
  64. if backgroundTaskIdentifier != .invalid {
  65. UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
  66. backgroundTaskIdentifier = .invalid
  67. }
  68. }
  69. func applicationWillEnterForeground(_ application: UIApplication) {
  70. checkAppConfig()
  71. }
  72. }
  73. extension AppDelegate {
  74. func checkAppConfig(){
  75. _ = TSNetworkShared.get(urlType: .config) { data,error in
  76. if let result = kNetWorkResultSuccess(data: data) {
  77. kAppNewVerison = result.safeString(forKey: "version")
  78. NotificationCenter.default.post(name: .kRefreshSettingView, object: nil)
  79. }
  80. }
  81. }
  82. }