SceneDelegate.swift 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. return window
  43. }()
  44. }
  45. }
  46. func sceneDidDisconnect(_ scene: UIScene) {
  47. // Called as the scene is being released by the system.
  48. // This occurs shortly after the scene enters the background, or when its session is discarded.
  49. // Release any resources associated with this scene that can be re-created the next time the scene connects.
  50. // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
  51. }
  52. func sceneDidBecomeActive(_ scene: UIScene) {
  53. // Called when the scene has moved from an inactive state to an active state.
  54. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
  55. }
  56. func sceneWillResignActive(_ scene: UIScene) {
  57. // Called when the scene will move from an active state to an inactive state.
  58. // This may occur due to temporary interruptions (ex. an incoming phone call).
  59. }
  60. func sceneWillEnterForeground(_ scene: UIScene) {
  61. // Called as the scene transitions from the background to the foreground.
  62. // Use this method to undo the changes made on entering the background.
  63. }
  64. func sceneDidEnterBackground(_ scene: UIScene) {
  65. // Called as the scene transitions from the foreground to the background.
  66. // Use this method to save data, release shared resources, and store enough scene-specific state information
  67. // to restore the scene back to its current state.
  68. }
  69. }
  70. struct InfoPList
  71. {
  72. private static func value(for name: String) -> String? { Bundle.main.object(forInfoDictionaryKey: name) as? String }
  73. static var bundleIdentifier: String? { self.value(for: "CFBundleIdentifier") }
  74. static var bundleDisplayName: String? { self.value(for: "CFBundleDisplayName") }
  75. static var bundleShortVersionString: String? { self.value(for: "CFBundleShortVersionString") }
  76. static var bundleVersion: String? { self.value(for: "CFBundleVersion") }
  77. static var launchStoryboardName: String? { self.value(for: "UILaunchStoryboardName") }
  78. static var mainStoryboardName: String? { self.value(for: "UIMainStoryboardFile") }
  79. }