Open History to see the last commit
1const { withAppDelegate, withInfoPlist } = require("expo/config-plugins");
2
3const SCENE_DELEGATE = `
4
5class SceneDelegate: UIResponder, UIWindowSceneDelegate {
6 var window: UIWindow?
7
8 func scene(
9 _ scene: UIScene,
10 willConnectTo session: UISceneSession,
11 options connectionOptions: UIScene.ConnectionOptions
12 ) {
13 guard
14 let windowScene = scene as? UIWindowScene,
15 let appDelegate = UIApplication.shared.delegate as? AppDelegate
16 else {
17 return
18 }
19
20 let appWindow: UIWindow
21 if let existingWindow = appDelegate.window {
22 appWindow = existingWindow
23 } else {
24 appWindow = UIWindow(windowScene: windowScene)
25 appDelegate.window = appWindow
26 appDelegate.reactNativeFactory?.startReactNative(
27 withModuleName: "main",
28 in: appWindow,
29 launchOptions: nil)
30 }
31
32 window = appWindow
33 appWindow.windowScene = windowScene
34 appWindow.makeKeyAndVisible()
35
36 if let url = connectionOptions.urlContexts.first?.url {
37 _ = appDelegate.application(UIApplication.shared, open: url, options: [:])
38 }
39
40 if let userActivity = connectionOptions.userActivities.first {
41 _ = appDelegate.application(
42 UIApplication.shared,
43 continue: userActivity,
44 restorationHandler: { _ in })
45 }
46 }
47
48 func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
49 guard
50 let url = URLContexts.first?.url,
51 let appDelegate = UIApplication.shared.delegate as? AppDelegate
52 else {
53 return
54 }
55
56 _ = appDelegate.application(UIApplication.shared, open: url, options: [:])
57 }
58
59 func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
60 guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
61 return
62 }
63
64 _ = appDelegate.application(
65 UIApplication.shared,
66 continue: userActivity,
67 restorationHandler: { _ in })
68 }
69}`;
70
71module.exports = function withIosSceneLifecycle(config) {
72 config = withInfoPlist(config, (nextConfig) => {
73 nextConfig.modResults.UIApplicationSceneManifest = {
74 UIApplicationSupportsMultipleScenes: false,
75 UISceneConfigurations: {
76 UIWindowSceneSessionRoleApplication: [
77 {
78 UISceneConfigurationName: "Default Configuration",
79 UISceneDelegateClassName: "$(PRODUCT_MODULE_NAME).SceneDelegate",
80 },
81 ],
82 },
83 };
84
85 return nextConfig;
86 });
87
88 return withAppDelegate(config, (nextConfig) => {
89 if (nextConfig.modResults.language !== "swift") {
90 throw new Error("The iOS scene lifecycle plugin requires a Swift AppDelegate.");
91 }
92
93 if (!nextConfig.modResults.contents.includes("class SceneDelegate:")) {
94 nextConfig.modResults.contents += SCENE_DELEGATE;
95 }
96
97 return nextConfig;
98 });
99};