SceneDelegate.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // SceneDelegate.swift
  3. // ACarouselDemo iOS
  4. //
  5. // Created by Autumn on 2020/11/16.
  6. //
  7. import UIKit
  8. import SwiftUI
  9. class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  10. var window: 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. // Create the SwiftUI view that provides the window contents.
  16. let contentView = ContentView()
  17. // Use a UIHostingController as window root view controller.
  18. if let windowScene = scene as? UIWindowScene {
  19. let window = UIWindow(windowScene: windowScene)
  20. window.rootViewController = UIHostingController(rootView: contentView)
  21. self.window = window
  22. window.makeKeyAndVisible()
  23. }
  24. }
  25. func sceneDidDisconnect(_ scene: UIScene) {
  26. // Called as the scene is being released by the system.
  27. // This occurs shortly after the scene enters the background, or when its session is discarded.
  28. // Release any resources associated with this scene that can be re-created the next time the scene connects.
  29. // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
  30. }
  31. func sceneDidBecomeActive(_ scene: UIScene) {
  32. // Called when the scene has moved from an inactive state to an active state.
  33. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
  34. }
  35. func sceneWillResignActive(_ scene: UIScene) {
  36. // Called when the scene will move from an active state to an inactive state.
  37. // This may occur due to temporary interruptions (ex. an incoming phone call).
  38. }
  39. func sceneWillEnterForeground(_ scene: UIScene) {
  40. // Called as the scene transitions from the background to the foreground.
  41. // Use this method to undo the changes made on entering the background.
  42. }
  43. func sceneDidEnterBackground(_ scene: UIScene) {
  44. // Called as the scene transitions from the foreground to the background.
  45. // Use this method to save data, release shared resources, and store enough scene-specific state information
  46. // to restore the scene back to its current state.
  47. }
  48. }