Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions examples/build-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,81 @@ In `demo/Info.plist`, add `UIBackgroundModes` and `NSSupportsLiveActivities` ins
<true/>
```

### 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 `<dict>`:

```xml
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
```

---

## 3. Notification Service Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
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 = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = demo/Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,6 +80,7 @@
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
A20000000000000000000011 /* demo.entitlements */,
0DAC812641FF641C181E6FF9 /* SceneDelegate.swift */,
);
name = demo;
sourceTree = "<group>";
Expand Down Expand Up @@ -318,6 +321,7 @@
buildActionMask = 2147483647;
files = (
761780ED2CA45674006654EE /* AppDelegate.swift in Sources */,
3A99B74EC18F86AAF2BEE957 /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
10 changes: 0 additions & 10 deletions examples/demo-no-location/ios/demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import ReactAppDependencyProvider

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

var reactNativeDelegate: ReactNativeDelegate?
var reactNativeFactory: RCTReactNativeFactory?

Expand All @@ -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
}
}
Expand Down
17 changes: 17 additions & 0 deletions examples/demo-no-location/ios/demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@
<true/>
<key>RCTNewArchEnabled</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
Expand Down
21 changes: 21 additions & 0 deletions examples/demo-no-location/ios/demo/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions examples/demo/ios/demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -88,6 +89,7 @@
A20000000000000000000011 /* demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = demo.entitlements; path = demo/demo.entitlements; sourceTree = "<group>"; };
B20000000000000000000001 /* template-bookmark-icon.png */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = image.png; name = "template-bookmark-icon.png"; path = "demo/template-bookmark-icon.png"; sourceTree = "<group>"; };
B20000000000000000000002 /* template-share-icon.png */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = image.png; name = "template-share-icon.png"; path = "demo/template-share-icon.png"; sourceTree = "<group>"; };
BEFF24CDEE2A22243C2367DC /* SceneDelegate.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = SceneDelegate.swift; path = demo/SceneDelegate.swift; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -132,6 +134,7 @@
A20000000000000000000011 /* demo.entitlements */,
B20000000000000000000001 /* template-bookmark-icon.png */,
B20000000000000000000002 /* template-share-icon.png */,
BEFF24CDEE2A22243C2367DC /* SceneDelegate.swift */,
);
name = demo;
sourceTree = "<group>";
Expand Down Expand Up @@ -474,6 +477,7 @@
buildActionMask = 2147483647;
files = (
761780ED2CA45674006654EE /* AppDelegate.swift in Sources */,
BB68C614BBE2B4BDEA04F2B6 /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
10 changes: 0 additions & 10 deletions examples/demo/ios/demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import ReactAppDependencyProvider

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

var reactNativeDelegate: ReactNativeDelegate?
var reactNativeFactory: RCTReactNativeFactory?

Expand All @@ -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
}
}
Expand Down
17 changes: 17 additions & 0 deletions examples/demo/ios/demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@
<true/>
<key>RCTNewArchEnabled</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
Expand Down
21 changes: 21 additions & 0 deletions examples/demo/ios/demo/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading