I am creating a React Native app with CarPlay assist utilizing the react-native-carplay library. The CarPlay interface works appropriately when the cellphone app is open, however it fails to load the JavaScript when the cellphone app is closed. Presently, the CarPlay doesn’t load the JS when the app is open both, though that’s one thing simpler to repair.
I already tried adhering to this README, though to little avail.
// AppDelegate.mm (redacted and consolidated)
@implementation AppDelegate
- (BOOL)initAppFromScene:(UISceneConnectionOptions *)connectionOptions {
if (self.rootView == nil) {
self.rootViewFactory = [self createRCTRootViewFactory];
NSDictionary *initProps = [self prepareInitialProps];
self.rootView = [self.rootViewFactory viewWithModuleName:self.moduleName
initialProperties:initProps
launchOptions:[self connectionOptionsToLaunchOptions:connectionOptions]];
return YES;
}
return NO;
}
// Different obligatory strategies...
@finish
// CarSceneDelegate.mm (redacted and consolidated)
@implementation CarSceneDelegate
- (void)templateApplicationScene:(CPTemplateApplicationScene *)templateApplicationScene
didConnectInterfaceController:(CPInterfaceController *)interfaceController {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate initAppFromScene:nil];
UIView *carPlayRootView = [appDelegate.rootViewFactory viewWithModuleName:@"CarPlayApp"
initialProperties:nil
launchOptions:nil];
UIViewController *rootViewController = appDelegate.createRootViewController;
[appDelegate setRootView:appDelegate.rootView toRootViewController:rootViewController];
CPWindow *carWindow = templateApplicationScene.carWindow;
carWindow.rootViewController = rootViewController;
[carPlayRootView setFrame:carWindow.bounds];
[carWindow addSubview:carPlayRootView];
[RNCarPlay connectWithInterfaceController:interfaceController window:carWindow];
}
// Different obligatory strategies...
@finish
// SceneDelegate.mm (redacted and consolidated)
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session choices:(UISceneConnectionOptions *)connectionOptions
{
if ([scene isKindOfClass:[UIWindowScene class]])
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
BOOL hasCreatedBridge = [appDelegate initAppFromScene:connectionOptions];
UIViewController *rootViewController = appDelegate.createRootViewController;
[appDelegate setRootView:appDelegate.rootView toRootViewController:rootViewController];
UIWindow *window = [[UIWindow alloc] initWithWindowScene:scene];
window.rootViewController = rootViewController;
self.window = window;
appDelegate.window = window;
[self.window makeKeyAndVisible];
// Deal with splash display...
}
}
// Different obligatory strategies...
@finish
// JavaScript
import { AppRegistry } from "react-native";
import CarCode from "./carplay/CarCode";
AppRegistry.registerComponent("CarPlayApp", () => CarCode);
I’ve tried numerous approaches, together with:
- Initializing the React Native bridge within the CarPlay scene delegate.
- Making a separate root view for CarPlay.
- Guaranteeing that the JavaScript bundle is loaded and executed.
Regardless of these makes an attempt, the CarPlay interface stays clean when the cellphone app shouldn’t be operating. The native iOS code appears to be working, however the JavaScript shouldn’t be being loaded or executed.
What am I lacking to make sure that the React Native JavaScript code runs in CarPlay even when the cellphone app is closed?
Further info:
React Native model: 75.0
react-native-carplay model: 2.4.1-beta.0
iOS model: 16.6
Any assist or insights can be enormously appreciated!