@@ -13,41 +13,42 @@ The Project name in this example is `Example`, which you should replace with you
1313
1414Create a new ` AppDelegate.swift ` file, once prompted, click * Create bridging headers for Swift* .
1515
16- Paste the following code to the ` AppDelegate.swift ` , it includes Flipper code .
16+ Paste the following code to the ` AppDelegate.swift ` .
1717
1818``` swift
1919// ios/AppDelegate.swift
2020import UIKit
2121import CarPlay
2222import React
23- #if DEBUG
24- #if FB_SONARKIT_ENABLED
25- import FlipperKit
26- #endif
27- #endif
2823
2924@main
3025class AppDelegate : UIResponder , UIApplicationDelegate , RCTBridgeDelegate {
3126
32- var window: UIWindow?
33- var bridge: RCTBridge? ;
34- var rootView: RCTRootView? ;
27+ var rootView: UIView?
28+
29+ override func application (_ application : UIApplication, didFinishLaunchingWithOptions launchOptions : [UIApplication.LaunchOptionsKey : Any ]? = nil ) -> Bool {
30+ moduleName = " RNCarPlayScene"
31+ initialProps = [: ]
3532
36- static var shared: AppDelegate { return UIApplication.shared .delegate as! AppDelegate }
33+ let app = super .application (application, didFinishLaunchingWithOptions : launchOptions)
34+ self .rootView = self .createRootView (
35+ with : self .bridge ! ,
36+ moduleName : self .moduleName ! ,
37+ initProps : self .initialProps !
38+ )
39+ return app
40+ }
3741
38- func sourceURL ( for bridge : RCTBridge ! ) -> URL! {
42+ override func bundleURL ( ) -> URL? {
3943 #if DEBUG
40- return RCTBundleURLProvider.sharedSettings ().jsBundleURL (forBundleRoot : " index" );
44+ return RCTBundleURLProvider.sharedSettings ().jsBundleURL (forBundleRoot : " index" )
4145 #else
4246 return Bundle.main .url (forResource :" main" , withExtension :" jsbundle" )
4347 #endif
4448 }
4549
46- func application (_ application : UIApplication, didFinishLaunchingWithOptions launchOptions : [UIApplication.LaunchOptionsKey: Any ]? ) -> Bool {
47- initializeFlipper (with : application)
48- self .bridge = RCTBridge.init (delegate : self , launchOptions : launchOptions)
49- self .rootView = RCTRootView.init (bridge : self .bridge ! , moduleName : " Example" , initialProperties : nil )
50- return true
50+ override func sourceURL (for bridge : RCTBridge) -> URL? {
51+ return bundleURL ()
5152 }
5253
5354 func application (_ application : UIApplication, configurationForConnecting connectingSceneSession : UISceneSession, options : UIScene.ConnectionOptions) -> UISceneConfiguration {
@@ -64,47 +65,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate {
6465
6566 func application (_ application : UIApplication, didDiscardSceneSessions sceneSessions : Set <UISceneSession>) {
6667 }
67-
68- private func initializeFlipper (with application : UIApplication) {
69- #if DEBUG
70- #if FB_SONARKIT_ENABLED
71- let client = FlipperClient.shared ()
72- let layoutDescriptorMapper = SKDescriptorMapper (defaults : ())
73- client? .add (FlipperKitLayoutPlugin (rootNode : application, with : layoutDescriptorMapper! ))
74- client? .add (FKUserDefaultsPlugin (suiteName : nil ))
75- client? .add (FlipperKitReactPlugin ())
76- client? .add (FlipperKitNetworkPlugin (networkAdapter : SKIOSNetworkAdapter ()))
77- client? .start ()
78- #endif
79- #endif
80- }
8168}
8269```
8370
8471Paste the following to your bridging header file ` Example-Bridging-Header.h ` :
8572
8673``` objc
8774// ios/Example-Bridging-Header.h
75+ #import < RCTAppDelegate.h>
8876#import " RNCarPlay.h"
89-
90- #ifdef DEBUG
91- #ifdef FB_SONARKIT_ENABLED
92- #import <FlipperKit/FlipperClient.h>
93- #import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
94- #import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
95- #import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
96- #import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
97- #import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
98- #endif
99- #endif
10077```
10178
102- ### 3. Add flags for Swift compiler in debug mode
79+ ### 3. Add flag for Swift compiler in debug mode
10380
104- Go to XCode project, hit ` Build Settings ` , search for ` Swift Compiler - Custom Flags ` and then under ` Active Compilation Conditions ` , add the following flags to ` Debug ` only:
81+ Go to XCode project, hit ` Build Settings ` , search for ` Swift Compiler - Custom Flags ` and then under ` Active Compilation Conditions ` , add the following flag to ` Debug ` only:
10582
10683 - DEBUG
107- - FB_SONARKIT_ENABLED
10884
10985### 4. Create Phone Scene
11086
@@ -119,11 +95,16 @@ import SwiftUI
11995class PhoneSceneDelegate : UIResponder , UIWindowSceneDelegate {
12096 var window: UIWindow?
12197 func scene (_ scene : UIScene, willConnectTo session : UISceneSession, options connectionOptions : UIScene.ConnectionOptions) {
98+
99+ if session.role != .windowApplication {
100+ return
101+ }
102+
122103 guard let appDelegate = (UIApplication.shared .delegate as? AppDelegate) else { return }
123104 guard let windowScene = (scene as? UIWindowScene) else { return }
124105
125106 let rootViewController = UIViewController ()
126- rootViewController.view = appDelegate.rootView ;
107+ rootViewController.view = appDelegate.rootView
127108
128109 let window = UIWindow (windowScene : windowScene)
129110 window.rootViewController = rootViewController
@@ -146,14 +127,15 @@ import CarPlay
146127class CarSceneDelegate : UIResponder , CPTemplateApplicationSceneDelegate {
147128 func templateApplicationScene (_ templateApplicationScene : CPTemplateApplicationScene,
148129 didConnect interfaceController : CPInterfaceController) {
149- RNCarPlay.connect (with : interfaceController, window : templateApplicationScene.carWindow );
130+ RNCarPlay.connect (with : interfaceController, window : templateApplicationScene.carWindow )
150131 }
151132
152133 func templateApplicationScene (_ templateApplicationScene : CPTemplateApplicationScene, didDisconnectInterfaceController interfaceController : CPInterfaceController) {
153134 RNCarPlay.disconnect ()
154135 }
155136}
156137
138+
157139```
158140
159141### 6. Update the manifest in Info.plist
0 commit comments