SceneDelegate.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // SceneDelegate.swift
  3. // TestQmeraLite
  4. //
  5. // Created by Qindi on 29/11/21.
  6. //
  7. import UIKit
  8. import NexilisLite
  9. class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  10. var window: UIWindow?
  11. var splashWindow: UIWindow?
  12. func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  13. // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
  14. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
  15. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
  16. guard let _ = (scene as? UIWindowScene) else { return }
  17. if let launchStoryboardName = InfoPList.launchStoryboardName,
  18. let windowScene = self.window?.windowScene
  19. {
  20. splashWindow = splashWindow ??
  21. {
  22. let window = UIWindow(windowScene: windowScene)
  23. window.windowLevel = .statusBar
  24. let storyboard = UIStoryboard(name: launchStoryboardName, bundle: nil)
  25. window.rootViewController = storyboard.instantiateInitialViewController()
  26. window.isHidden = false
  27. // ⏳Wait for 5 seconds, then remove.
  28. //
  29. DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1))
  30. {
  31. UIView.animate(withDuration: -1, // system default
  32. animations:
  33. {
  34. self.splashWindow?.alpha = 0
  35. },
  36. completion:
  37. { _ in
  38. self.splashWindow?.isHidden = true
  39. self.splashWindow = nil
  40. }
  41. )
  42. }
  43. let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
  44. tabBarAppearance.configureWithTransparentBackground()
  45. if let rootViewController = window.rootViewController {
  46. // Check if dark mode is enabled
  47. let isDarkMode = rootViewController.traitCollection.userInterfaceStyle == .dark
  48. if isDarkMode {
  49. tabBarAppearance.backgroundColor = .black.withAlphaComponent(0.7)
  50. } else {
  51. tabBarAppearance.backgroundColor = .white.withAlphaComponent(0.9)
  52. }
  53. if Utils.getReverseTab() == "1" {
  54. tabBarAppearance.backgroundColor = .black.withAlphaComponent(0.7)
  55. }
  56. }
  57. if #available(iOS 13.0, *) {
  58. UITabBar.appearance().standardAppearance = tabBarAppearance
  59. }
  60. if #available(iOS 15.0, *) {
  61. UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
  62. }
  63. return window
  64. }()
  65. }
  66. }
  67. func sceneDidDisconnect(_ scene: UIScene) {
  68. // Called as the scene is being released by the system.
  69. // This occurs shortly after the scene enters the background, or when its session is discarded.
  70. // Release any resources associated with this scene that can be re-created the next time the scene connects.
  71. // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
  72. }
  73. func sceneDidBecomeActive(_ scene: UIScene) {
  74. // Called when the scene has moved from an inactive state to an active state.
  75. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
  76. APIS.enterForeground()
  77. }
  78. func sceneWillResignActive(_ scene: UIScene) {
  79. // Called when the scene will move from an active state to an inactive state.
  80. // This may occur due to temporary interruptions (ex. an incoming phone call).
  81. }
  82. func sceneWillEnterForeground(_ scene: UIScene) {
  83. // Called as the scene transitions from the background to the foreground.
  84. // Use this method to undo the changes made on entering the background.
  85. }
  86. func sceneDidEnterBackground(_ scene: UIScene) {
  87. // Called as the scene transitions from the foreground to the background.
  88. // Use this method to save data, release shared resources, and store enough scene-specific state information
  89. // to restore the scene back to its current state.
  90. APIS.enterBackground()
  91. }
  92. }
  93. struct InfoPList
  94. {
  95. private static func value(for name: String) -> String? { Bundle.main.object(forInfoDictionaryKey: name) as? String }
  96. static var bundleIdentifier: String? { self.value(for: "CFBundleIdentifier") }
  97. static var bundleDisplayName: String? { self.value(for: "CFBundleDisplayName") }
  98. static var bundleShortVersionString: String? { self.value(for: "CFBundleShortVersionString") }
  99. static var bundleVersion: String? { self.value(for: "CFBundleVersion") }
  100. static var launchStoryboardName: String? { self.value(for: "UILaunchStoryboardName") }
  101. static var mainStoryboardName: String? { self.value(for: "UIMainStoryboardFile") }
  102. }