SceneDelegate.swift 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 SwiftUI
  15. import UIKit
  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
  21. // UIWindowScene `scene`.
  22. // If using a storyboard, the `window` property will automatically be initialized and attached
  23. // to the scene.
  24. // This delegate does not imply the connecting scene or session are new (see
  25. // `application:configurationForConnectingSceneSession` instead).
  26. // Create the SwiftUI view that provides the window contents.
  27. let contentView = ContentView()
  28. // Use a UIHostingController as window root view controller.
  29. if let windowScene = scene as? UIWindowScene {
  30. let window = UIWindow(windowScene: windowScene)
  31. window.rootViewController = UIHostingController(rootView: contentView)
  32. self.window = window
  33. window.makeKeyAndVisible()
  34. }
  35. }
  36. func sceneDidDisconnect(_ scene: UIScene) {
  37. // Called as the scene is being released by the system.
  38. // This occurs shortly after the scene enters the background, or when its session is discarded.
  39. // Release any resources associated with this scene that can be re-created the next time the
  40. // scene connects.
  41. // The scene may re-connect later, as its session was not necessarily discarded (see
  42. // `application:didDiscardSceneSessions` instead).
  43. }
  44. func sceneDidBecomeActive(_ scene: UIScene) {
  45. // Called when the scene has moved from an inactive state to an active state.
  46. // Use this method to restart any tasks that were paused (or not yet started) when the scene was
  47. // inactive.
  48. }
  49. func sceneWillResignActive(_ scene: UIScene) {
  50. // Called when the scene will move from an active state to an inactive state.
  51. // This may occur due to temporary interruptions (ex. an incoming phone call).
  52. }
  53. func sceneWillEnterForeground(_ scene: UIScene) {
  54. // Called as the scene transitions from the background to the foreground.
  55. // Use this method to undo the changes made on entering the background.
  56. }
  57. func sceneDidEnterBackground(_ scene: UIScene) {
  58. // Called as the scene transitions from the foreground to the background.
  59. // Use this method to save data, release shared resources, and store enough scene-specific state
  60. // information
  61. // to restore the scene back to its current state.
  62. }
  63. }