SceneDelegate.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // SceneDelegate.swift
  3. // DemoApp
  4. //
  5. // Created by wesley on 2021/6/21.
  6. //
  7. import UIKit
  8. class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  9. var window: UIWindow?
  10. @available(iOS 13.0, *)
  11. func scene(_ scene: UIScene,
  12. willConnectTo session: UISceneSession,
  13. options connectionOptions: UIScene.ConnectionOptions) {
  14. guard let windowScene = (scene as? UIWindowScene) else { return }
  15. window = UIWindow(windowScene: windowScene)
  16. window?.backgroundColor = UIColor.white
  17. processOfflinePush(connectionOptions: connectionOptions)
  18. let loginVC = TRTCLoginViewController()
  19. let nav = RoomNavigationController(rootViewController: loginVC)
  20. window?.rootViewController = nav
  21. window?.makeKeyAndVisible()
  22. }
  23. private func processOfflinePush(connectionOptions: UIScene.ConnectionOptions) {
  24. guard let pushNotification = connectionOptions.notificationResponse?.notification.request.content.userInfo else { return }
  25. guard let extString = pushNotification["ext"] as? String else { return }
  26. guard let dict = extString.convertToDic() else { return }
  27. guard let roomId = dict["RoomId"] as? String else { return }
  28. guard let notificationType = dict["NotificationType"] as? String else { return }
  29. AppUtils.shared.roomId = roomId
  30. AppUtils.shared.notificationType = notificationType
  31. AppUtils.shared.extString = extString
  32. }
  33. static func getCurrentWindow() -> UIWindow? {
  34. if #available(iOS 13, *) {
  35. if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
  36. if let keyWindow = windowScene.windows.first {
  37. return keyWindow
  38. }
  39. }
  40. } else {
  41. for window in UIApplication.shared.windows {
  42. if window.isMember(of: UIWindow.self), window.isKeyWindow {
  43. return window
  44. }
  45. }
  46. }
  47. return nil
  48. }
  49. }