|
| 1 | +import UIKit |
| 2 | +import React_RCTAppDelegate |
| 3 | + |
| 4 | +class SceneDelegate: UIResponder, UIWindowSceneDelegate { |
| 5 | + var window: UIWindow? |
| 6 | + |
| 7 | + func scene( |
| 8 | + _ scene: UIScene, |
| 9 | + willConnectTo session: UISceneSession, |
| 10 | + options connectionOptions: UIScene.ConnectionOptions |
| 11 | + ) { |
| 12 | + guard let windowScene = scene as? UIWindowScene else { return } |
| 13 | + guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, |
| 14 | + let factory = appDelegate.reactNativeFactory else { |
| 15 | + assertionFailure("React Native must be initialized before connecting a scene") |
| 16 | + return |
| 17 | + } |
| 18 | + |
| 19 | + let window = UIWindow(windowScene: windowScene) |
| 20 | + self.window = window |
| 21 | + appDelegate.window = window |
| 22 | + |
| 23 | + var launchOptions = appDelegate.launchOptions ?? [:] |
| 24 | + if let url = connectionOptions.urlContexts.first?.url { |
| 25 | + launchOptions[.url] = url |
| 26 | + } |
| 27 | + |
| 28 | + factory.startReactNative( |
| 29 | + withModuleName: "main", |
| 30 | + in: window, |
| 31 | + launchOptions: launchOptions |
| 32 | + ) |
| 33 | + } |
| 34 | + |
| 35 | + func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { |
| 36 | + guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } |
| 37 | + |
| 38 | + for context in URLContexts { |
| 39 | + _ = appDelegate.application(UIApplication.shared, open: context.url) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { |
| 44 | + guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } |
| 45 | + _ = appDelegate.application(UIApplication.shared, continue: userActivity) { _ in } |
| 46 | + } |
| 47 | + |
| 48 | + func sceneDidBecomeActive(_ scene: UIScene) { |
| 49 | + (UIApplication.shared.delegate as? AppDelegate)?.applicationDidBecomeActive(UIApplication.shared) |
| 50 | + } |
| 51 | + |
| 52 | + func sceneWillResignActive(_ scene: UIScene) { |
| 53 | + (UIApplication.shared.delegate as? AppDelegate)?.applicationWillResignActive(UIApplication.shared) |
| 54 | + } |
| 55 | + |
| 56 | + func sceneDidEnterBackground(_ scene: UIScene) { |
| 57 | + (UIApplication.shared.delegate as? AppDelegate)?.applicationDidEnterBackground(UIApplication.shared) |
| 58 | + } |
| 59 | + |
| 60 | + func sceneWillEnterForeground(_ scene: UIScene) { |
| 61 | + (UIApplication.shared.delegate as? AppDelegate)?.applicationWillEnterForeground(UIApplication.shared) |
| 62 | + } |
| 63 | +} |
0 commit comments