SceneDelegate.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import UIKit
  15. import SwiftUI
  16. class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  17. var window: UIWindow?
  18. func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
  19. options connectionOptions: UIScene.ConnectionOptions) {
  20. // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
  21. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
  22. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
  23. // Create the SwiftUI view that provides the window contents.
  24. let contentView = ContentView()
  25. // Use a UIHostingController as window root view controller.
  26. if let windowScene = scene as? UIWindowScene {
  27. let window = UIWindow(windowScene: windowScene)
  28. window.rootViewController = UIHostingController(rootView: contentView)
  29. self.window = window
  30. window.makeKeyAndVisible()
  31. }
  32. }
  33. func sceneDidDisconnect(_ scene: UIScene) {
  34. // Called as the scene is being released by the system.
  35. // This occurs shortly after the scene enters the background, or when its session is discarded.
  36. // Release any resources associated with this scene that can be re-created the next time the scene connects.
  37. // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
  38. }
  39. func sceneDidBecomeActive(_ scene: UIScene) {
  40. // Called when the scene has moved from an inactive state to an active state.
  41. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
  42. }
  43. func sceneWillResignActive(_ scene: UIScene) {
  44. // Called when the scene will move from an active state to an inactive state.
  45. // This may occur due to temporary interruptions (ex. an incoming phone call).
  46. }
  47. func sceneWillEnterForeground(_ scene: UIScene) {
  48. // Called as the scene transitions from the background to the foreground.
  49. // Use this method to undo the changes made on entering the background.
  50. }
  51. func sceneDidEnterBackground(_ scene: UIScene) {
  52. // Called as the scene transitions from the foreground to the background.
  53. // Use this method to save data, release shared resources, and store enough scene-specific state information
  54. // to restore the scene back to its current state.
  55. }
  56. }