UIApplication+Extension.swift 1.0 KB

1234567891011121314151617181920212223242526272829
  1. //
  2. // UIApplication+Extension.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 25/03/24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. extension UIApplication {
  11. var firstWindow: UIWindow? {
  12. let windowScenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
  13. let firstActiveScene = windowScenes.first
  14. let keyWindow = firstActiveScene?.keyWindow
  15. return keyWindow
  16. }
  17. func allSceneSessionDestructionExceptFirst() {
  18. let windowScenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
  19. let firstActiveScene = windowScenes.first
  20. let options = UIWindowSceneDestructionRequestOptions()
  21. options.windowDismissalAnimation = .standard
  22. for windowScene in windowScenes {
  23. if windowScene == firstActiveScene { continue }
  24. requestSceneSessionDestruction(windowScene.session, options: options, errorHandler: nil)
  25. }
  26. }
  27. }