Repository navigation
Fix iOS scene lifecycle startup #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| const fs = require("node:fs"); | ||
| const path = require("node:path"); | ||
| const { withDangerousMod, withInfoPlist, withXcodeProject } = require("expo/config-plugins"); | ||
|
|
||
| const sceneDelegate = `import UIKit | ||
|
|
||
| final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
| var window: UIWindow? | ||
|
|
||
| func scene( | ||
| _ scene: UIScene, | ||
| willConnectTo session: UISceneSession, | ||
| options connectionOptions: UIScene.ConnectionOptions | ||
| ) { | ||
| guard let windowScene = scene as? UIWindowScene else { return } | ||
| guard let appWindow = (UIApplication.shared.delegate as? AppDelegate)?.window else { return } | ||
| appWindow.windowScene = windowScene | ||
| window = appWindow | ||
| appWindow.makeKeyAndVisible() | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| function withIOSSceneLifecycle(config) { | ||
| config = withInfoPlist(config, (mod) => { | ||
| mod.modResults.UIApplicationSceneManifest = { | ||
| UIApplicationSupportsMultipleScenes: false, | ||
| UISceneConfigurations: { | ||
| UIWindowSceneSessionRoleApplication: [ | ||
| { | ||
| UISceneConfigurationName: "Default Configuration", | ||
| UISceneDelegateClassName: "$(PRODUCT_MODULE_NAME).SceneDelegate", | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
| return mod; | ||
| }); | ||
|
|
||
| config = withDangerousMod(config, [ | ||
| "ios", | ||
| async (mod) => { | ||
| const filePath = path.join( | ||
| mod.modRequest.platformProjectRoot, | ||
| mod.modRequest.projectName, | ||
| "SceneDelegate.swift", | ||
| ); | ||
| fs.writeFileSync(filePath, sceneDelegate); | ||
| return mod; | ||
| }, | ||
| ]); | ||
|
|
||
| return withXcodeProject(config, (mod) => { | ||
| const project = mod.modResults; | ||
| const target = project.getFirstTarget(); | ||
| if (!project.hasFile("OpenMuse/SceneDelegate.swift")) | ||
| project.addSourceFile("OpenMuse/SceneDelegate.swift", { target: target.uuid }, "OpenMuse"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] node-xcode expects the PBX group UUID as addSourceFile's third argument, not the display name 'OpenMuse'. In a fresh Expo iOS prebuild this invokes getPBXVariantGroupByKey('OpenMuse') and throws Cannot read properties of undefined (reading 'OpenMuse'), blocking native project generation. The same clean prebuild passes when only this plugin is removed. Resolve the actual project group key and add clean-prebuild regression/validation. |
||
| return mod; | ||
| }); | ||
| } | ||
|
|
||
| module.exports = withIOSSceneLifecycle; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] This UIWindowSceneDelegate only attaches the window and does not forward cold-start connectionOptions or subsequent scene URL events. After adopting scenes UIKit stops invoking application(_:open:options:), which the generated AppDelegate/Expo dev-launcher currently uses. Preserve cold/warm URL and user-activity delivery when migrating; see Expo's guide: https://github.com/expo/fyi/blob/main/ios-scene-lifecycle.md. Validate development-client launch links on the migrated project.