diff --git a/examples/build-ios.md b/examples/build-ios.md index f662a8d8..d7504958 100644 --- a/examples/build-ios.md +++ b/examples/build-ios.md @@ -58,6 +58,81 @@ In `demo/Info.plist`, add `UIBackgroundModes` and `NSSupportsLiveActivities` ins ``` +### Scene lifecycle + +Apps built with the iOS 27 SDK must use the UIScene lifecycle, or they crash at launch. The app delegate creates the React Native factory, and a scene delegate starts React Native in the scene's window. + +In `demo/AppDelegate.swift`, create the factory but no window: + +```swift +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + var reactNativeDelegate: ReactNativeDelegate? + var reactNativeFactory: RCTReactNativeFactory? + + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil + ) -> Bool { + let delegate = ReactNativeDelegate() + let factory = RCTReactNativeFactory(delegate: delegate) + delegate.dependencyProvider = RCTAppDependencyProvider() + + reactNativeDelegate = delegate + reactNativeFactory = factory + + return true + } +} +``` + +Create `demo/SceneDelegate.swift` and add it to the `demo` target: + +```swift +import UIKit +import React + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + var window: UIWindow? + + func scene( + _ scene: UIScene, + willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions + ) { + guard let windowScene = scene as? UIWindowScene, + let appDelegate = UIApplication.shared.delegate as? AppDelegate, + let factory = appDelegate.reactNativeFactory else { return } + + let window = UIWindow(windowScene: windowScene) + self.window = window + factory.startReactNative(withModuleName: "demo", in: window, launchOptions: nil) + } +} +``` + +In `demo/Info.plist`, add the scene manifest inside the top-level ``: + +```xml +UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + + + + +``` + --- ## 3. Notification Service Extension diff --git a/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj b/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj index 97e4f62a..88608287 100644 --- a/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj +++ b/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 0C80B921A6F3F58F76C31292 /* libPods-demo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-demo.a */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; + 3A99B74EC18F86AAF2BEE957 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DAC812641FF641C181E6FF9 /* SceneDelegate.swift */; }; 5F8F7D5C84F8947D278D5B06 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */; }; 761780ED2CA45674006654EE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 761780EC2CA45674006654EE /* AppDelegate.swift */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; @@ -28,6 +29,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0DAC812641FF641C181E6FF9 /* SceneDelegate.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = SceneDelegate.swift; path = demo/SceneDelegate.swift; sourceTree = ""; }; 13B07F961A680F5B00A75B9A /* demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = demo/Images.xcassets; sourceTree = ""; }; 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = demo/Info.plist; sourceTree = ""; }; @@ -78,6 +80,7 @@ 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */, A20000000000000000000011 /* demo.entitlements */, + 0DAC812641FF641C181E6FF9 /* SceneDelegate.swift */, ); name = demo; sourceTree = ""; @@ -318,6 +321,7 @@ buildActionMask = 2147483647; files = ( 761780ED2CA45674006654EE /* AppDelegate.swift in Sources */, + 3A99B74EC18F86AAF2BEE957 /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/examples/demo-no-location/ios/demo/AppDelegate.swift b/examples/demo-no-location/ios/demo/AppDelegate.swift index 8b1f26fc..8685fb14 100644 --- a/examples/demo-no-location/ios/demo/AppDelegate.swift +++ b/examples/demo-no-location/ios/demo/AppDelegate.swift @@ -5,8 +5,6 @@ import ReactAppDependencyProvider @main class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? - var reactNativeDelegate: ReactNativeDelegate? var reactNativeFactory: RCTReactNativeFactory? @@ -21,14 +19,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { reactNativeDelegate = delegate reactNativeFactory = factory - window = UIWindow(frame: UIScreen.main.bounds) - - factory.startReactNative( - withModuleName: "demo", - in: window, - launchOptions: launchOptions - ) - return true } } diff --git a/examples/demo-no-location/ios/demo/Info.plist b/examples/demo-no-location/ios/demo/Info.plist index 8b154398..8928b02f 100644 --- a/examples/demo-no-location/ios/demo/Info.plist +++ b/examples/demo-no-location/ios/demo/Info.plist @@ -37,6 +37,23 @@ RCTNewArchEnabled + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + + + + UIBackgroundModes remote-notification diff --git a/examples/demo-no-location/ios/demo/SceneDelegate.swift b/examples/demo-no-location/ios/demo/SceneDelegate.swift new file mode 100644 index 00000000..6a6b1584 --- /dev/null +++ b/examples/demo-no-location/ios/demo/SceneDelegate.swift @@ -0,0 +1,21 @@ +import UIKit +import React + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + var window: UIWindow? + + func scene( + _ scene: UIScene, + willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions + ) { + guard let windowScene = scene as? UIWindowScene, + let appDelegate = UIApplication.shared.delegate as? AppDelegate, + let factory = appDelegate.reactNativeFactory else { return } + + let window = UIWindow(windowScene: windowScene) + self.window = window + + factory.startReactNative(withModuleName: "demo", in: window, launchOptions: nil) + } +} diff --git a/examples/demo/ios/demo.xcodeproj/project.pbxproj b/examples/demo/ios/demo.xcodeproj/project.pbxproj index 1a7dfaf2..43d26c1c 100644 --- a/examples/demo/ios/demo.xcodeproj/project.pbxproj +++ b/examples/demo/ios/demo.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ B10000000000000000000002 /* template-share-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = B20000000000000000000002 /* template-share-icon.png */; }; B10000000000000000000003 /* template-bookmark-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = B20000000000000000000001 /* template-bookmark-icon.png */; }; B10000000000000000000004 /* template-share-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = B20000000000000000000002 /* template-share-icon.png */; }; + BB68C614BBE2B4BDEA04F2B6 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEFF24CDEE2A22243C2367DC /* SceneDelegate.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -88,6 +89,7 @@ A20000000000000000000011 /* demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = demo.entitlements; path = demo/demo.entitlements; sourceTree = ""; }; B20000000000000000000001 /* template-bookmark-icon.png */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = image.png; name = "template-bookmark-icon.png"; path = "demo/template-bookmark-icon.png"; sourceTree = ""; }; B20000000000000000000002 /* template-share-icon.png */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = image.png; name = "template-share-icon.png"; path = "demo/template-share-icon.png"; sourceTree = ""; }; + BEFF24CDEE2A22243C2367DC /* SceneDelegate.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = SceneDelegate.swift; path = demo/SceneDelegate.swift; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -132,6 +134,7 @@ A20000000000000000000011 /* demo.entitlements */, B20000000000000000000001 /* template-bookmark-icon.png */, B20000000000000000000002 /* template-share-icon.png */, + BEFF24CDEE2A22243C2367DC /* SceneDelegate.swift */, ); name = demo; sourceTree = ""; @@ -474,6 +477,7 @@ buildActionMask = 2147483647; files = ( 761780ED2CA45674006654EE /* AppDelegate.swift in Sources */, + BB68C614BBE2B4BDEA04F2B6 /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/examples/demo/ios/demo/AppDelegate.swift b/examples/demo/ios/demo/AppDelegate.swift index 8b1f26fc..8685fb14 100644 --- a/examples/demo/ios/demo/AppDelegate.swift +++ b/examples/demo/ios/demo/AppDelegate.swift @@ -5,8 +5,6 @@ import ReactAppDependencyProvider @main class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? - var reactNativeDelegate: ReactNativeDelegate? var reactNativeFactory: RCTReactNativeFactory? @@ -21,14 +19,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { reactNativeDelegate = delegate reactNativeFactory = factory - window = UIWindow(frame: UIScreen.main.bounds) - - factory.startReactNative( - withModuleName: "demo", - in: window, - launchOptions: launchOptions - ) - return true } } diff --git a/examples/demo/ios/demo/Info.plist b/examples/demo/ios/demo/Info.plist index 56bc2120..2b100729 100644 --- a/examples/demo/ios/demo/Info.plist +++ b/examples/demo/ios/demo/Info.plist @@ -39,6 +39,23 @@ RCTNewArchEnabled + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + + + + UIBackgroundModes remote-notification diff --git a/examples/demo/ios/demo/SceneDelegate.swift b/examples/demo/ios/demo/SceneDelegate.swift new file mode 100644 index 00000000..6a6b1584 --- /dev/null +++ b/examples/demo/ios/demo/SceneDelegate.swift @@ -0,0 +1,21 @@ +import UIKit +import React + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + var window: UIWindow? + + func scene( + _ scene: UIScene, + willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions + ) { + guard let windowScene = scene as? UIWindowScene, + let appDelegate = UIApplication.shared.delegate as? AppDelegate, + let factory = appDelegate.reactNativeFactory else { return } + + let window = UIWindow(windowScene: windowScene) + self.window = window + + factory.startReactNative(withModuleName: "demo", in: window, launchOptions: nil) + } +}