SceneDelegate.swift 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // SceneDelegate.swift
  3. // naiyoup
  4. //
  5. // Created by C Auto on 2021/5/27.
  6. //
  7. import UIKit
  8. import SwiftUI
  9. import IQKeyboardManagerSwift
  10. import XCGLogger
  11. var log = XCGLogger.default
  12. class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  13. var window: UIWindow?
  14. func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  15. IQKeyboardManager.shared.enable = true
  16. configLogger()
  17. NetWorkTools.GetBaidu()
  18. // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
  19. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
  20. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
  21. // Create the SwiftUI view that provides the window contents.
  22. let contentView = ContentView()
  23. // Use a UIHostingController as window root view controller.
  24. if let windowScene = scene as? UIWindowScene {
  25. let window = UIWindow(windowScene: windowScene)
  26. window.rootViewController = MyHontingController(rootView: AnyView(contentView))
  27. self.window = window
  28. window.makeKeyAndVisible()
  29. }
  30. }
  31. func sceneDidDisconnect(_ scene: UIScene) {
  32. // Called as the scene is being released by the system.
  33. // This occurs shortly after the scene enters the background, or when its session is discarded.
  34. // Release any resources associated with this scene that can be re-created the next time the scene connects.
  35. // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
  36. }
  37. func sceneDidBecomeActive(_ scene: UIScene) {
  38. // Called when the scene has moved from an inactive state to an active state.
  39. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
  40. }
  41. func sceneWillResignActive(_ scene: UIScene) {
  42. // Called when the scene will move from an active state to an inactive state.
  43. // This may occur due to temporary interruptions (ex. an incoming phone call).
  44. }
  45. func sceneWillEnterForeground(_ scene: UIScene) {
  46. // Called as the scene transitions from the background to the foreground.
  47. // Use this method to undo the changes made on entering the background.
  48. }
  49. func sceneDidEnterBackground(_ scene: UIScene) {
  50. // Called as the scene transitions from the foreground to the background.
  51. // Use this method to save data, release shared resources, and store enough scene-specific state information
  52. // to restore the scene back to its current state.
  53. }
  54. func configLogger() {
  55. // Create a logger object with no destinations
  56. log = XCGLogger(identifier: "advancedLogger", includeDefaultDestinations: false)
  57. // Create a destination for the system console log (via NSLog)
  58. let systemDestination = AppleSystemLogDestination(identifier: "advancedLogger.systemDestination")
  59. // Optionally set some configuration options
  60. systemDestination.outputLevel = .info
  61. systemDestination.showLogIdentifier = false
  62. systemDestination.showFunctionName = true
  63. systemDestination.showThreadName = true
  64. systemDestination.showLevel = true
  65. systemDestination.showFileName = true
  66. systemDestination.showLineNumber = true
  67. systemDestination.showDate = true
  68. // Add the destination to the logger
  69. log.add(destination: systemDestination)
  70. log.logAppDetails()
  71. }
  72. }