ChatApp.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // ChatApp.swift
  3. // Shared
  4. //
  5. // Created by Sergey Tarasov on 24.07.2022.
  6. //
  7. import SwiftUI
  8. import XMPPFramework
  9. @main
  10. struct ChatApp: App {
  11. @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
  12. var body: some Scene {
  13. WindowGroup {
  14. ContentView()
  15. .onAppear(perform: UIApplication.shared.addTapGestureRecognizer)
  16. }
  17. }
  18. }
  19. class AppDelegate: NSObject, UIApplicationDelegate {
  20. func application(
  21. _ application: UIApplication,
  22. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
  23. ) -> Bool {
  24. DDLog.add(DDOSLogger.sharedInstance, with: DDLogLevel.all)
  25. return true
  26. }
  27. }
  28. extension UIApplication {
  29. func addTapGestureRecognizer() {
  30. let scenes = UIApplication.shared.connectedScenes
  31. let windowScene = scenes.first as? UIWindowScene
  32. guard let window = windowScene?.windows.first else { return }
  33. let tapGesture = UITapGestureRecognizer(target: window, action: #selector(UIView.endEditing))
  34. tapGesture.requiresExclusiveTouchType = false
  35. tapGesture.cancelsTouchesInView = false
  36. tapGesture.delegate = self
  37. window.addGestureRecognizer(tapGesture)
  38. }
  39. }
  40. extension UIApplication: UIGestureRecognizerDelegate {
  41. public func gestureRecognizer(
  42. _ gestureRecognizer: UIGestureRecognizer,
  43. shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer
  44. ) -> Bool {
  45. return false
  46. }
  47. }