SceneDelegate.swift 6.2 KB

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