Skip to content

React Native App with implemented Carplay doesnt show content on carplay screen if IPhone App is terminated #41777

@zerobertelprivat

Description

@zerobertelprivat

Description

I have build a well working React Native App (thanks to the RN Team and supporters) with the ability to play podcasts via App and Carplay. To implement Carplay i have splitted the App in 2 Scenes via the Info.plist. Additional adjustments in the AppDelegate.m were also neccessary, i have copied the whole RCT AppDelegate to ensure the correct sequence of code in the adjusted function:

`
@implementation AppDelegate

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
/

Original Code Start
-> code of clean default function
*/
self.moduleName = @"app";
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};

// return [super application:application didFinishLaunchingWithOptions:launchOptions]
// ^^ removed because of SceneDelegate logic for carplay
/*
Original Code End
*/

/*
CUSTOM_IMPLEMENTATION_START
*/

/*
IMPORTANT NOTE:
whole following code replaces
return [super application:application didFinishLaunchingWithOptions:launchOptions];
of original version
-> neccessary to split app in scenes for carplay
-> after every React Native Update you have to copy code Sections of the RCTAppDelegate "application"
function except the uncomment "self.window" etc code
*/

/*
Copied code from RCTAppDelegate application function (start)
*/
BOOL enableTM = NO;
#if RCT_NEW_ARCH_ENABLED
enableTM = self.turboModuleEnabled;
#endif
RCTAppSetupPrepareApp(application, enableTM);

if (!self.bridge) {
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
}
#if RCT_NEW_ARCH_ENABLED
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
contextContainer:_contextContainer];
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;

[self unstable_registerLegacyComponents];
#endif

NSDictionary *initProps = [self prepareInitialProps];
UIView *rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];

// self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// UIViewController *rootViewController = [self createRootViewController];
// rootViewController.view = rootView;
// self.window.rootViewController = rootViewController;
// [self.window makeKeyAndVisible];
// ^^
// ^^ Ignored Code from RCTAppDelegate because of SceneDelegate logic for carplay
// ^^ Code is moved into SceneDelegate class

/*
Copied code from RCTAppDelegate application function (end)
*/

// make bridge and rootview shareable to enable acces from SceneDelegate
[[[RNBridgeInstanceHolderObjC alloc]init] setBridgeAndRootView:(self.bridge) rootView:(rootView)]; // custom_carplay

[RNSplashScreen show]; // custom_splashscreen

/*
Copied code from RCTAppDelegate application function (start)
/
return YES;
/

Copied code from RCTAppDelegate application function (end)
*/

/*
CUSTOM_IMPLEMENTATION_END
*/
}

/*
CUSTOM_IMPLEMENTATION_START
*/
// Copied code from RCTAppDelegate (start)

  • (NSDictionary *)prepareInitialProps
    {
    NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new];

#ifdef RCT_NEW_ARCH_ENABLED
// Hardcoding the Concurrent Root as it it not recommended to
// have the concurrentRoot turned off when Fabric is enabled.
initProps[kRNConcurrentRoot] = @([self fabricEnabled]);
#endif

return initProps;
}
// Copied code from RCTAppDelegate (end)
/*
CUSTOM_IMPLEMENTATION_END
*/
`

No the Problem is: Music Apps like Spotify, Tidal etc show carplay content if the phone apps are terminated and i click on the App Icon in Carplay Simulator. My App doesnt so, it shows an empty screen. If the phone app is in background or active, everything is working well. I have no idea what i am doing wrong. Please help! Thanks in advance!

Some code of the CarPlay SceneDelegate:

import Foundation import CarPlay class SceneDelegateCarPlay: UIResponder, CPTemplateApplicationSceneDelegate { ... func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) { print("SceneDelegateCarPlay.templateApplicationScene(), didConnect") // start render content ... }

"templateApplicationScene" is called and render content when:

  1. Carplay App is closed & Iphone App is active or in background -> Click on Carplay App Icon
  2. Carplay App is open (no content visible) & Iphone App is terminated -> Start Iphone App

I wonder how i can render content outside of a case like these

React Native Version

0.72.7

Output of npx react-native info

System:
OS: macOS 14.1.1
CPU: (10) arm64 Apple M1 Pro
Memory: 98.50 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 16.17.1
path: ~/.nvm/versions/node/v16.17.1/bin/node
Yarn:
version: 1.22.19
path: ~/Projekte/Mediapioneer/app/node_modules/.bin/yarn
npm:
version: 8.15.0
path: ~/.nvm/versions/node/v16.17.1/bin/npm
Watchman:
version: 2023.10.23.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.14.3
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.0
- iOS 17.0
- macOS 14.0
- tvOS 17.0
- watchOS 10.0
Android SDK: Not Found
IDEs:
Android Studio: 2022.3 AI-223.8836.35.2231.11090377
Xcode:
version: 15.0.1/15A507
path: /usr/bin/xcodebuild
Languages:
Java:
version: 11.0.16.1
path: /usr/bin/javac
Ruby:
version: 3.2.2
path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.7
wanted: 0.72.7
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Steps to reproduce

See description

Snack, screenshot, or link to a repository

Bildschirmfoto 2023-12-04 um 07 42 04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: AnsweredWhen the issue is resolved with a simple answer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions