Skip to content

feat(ios): CarPlay prototype on the shared navigation session - #17

Merged
mfazekas merged 15 commits into
mainfrom
feat/carplay-prototype
Oct 27, 2026
Merged

mfazekas merged 15 commits into
mainfrom
feat/carplay-prototype

Conversation

@mfazekas

@mfazekas mfazekas commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Draft prototype. Not ready to merge.

Design

  1. Scenes. CarPlay needs a CPTemplateApplicationSceneSessionRoleApplication scene. Expo SDK 58 apps already use the scene-based life cycle: UIApplicationSceneManifest has a phone scene whose ExpoAppSceneDelegate creates the window, and the app delegate still creates the React Native factory. So the CarPlay scene can sit next to the phone scene without touching the app delegate or ExpoAppDelegateSubscriber. The pod ships RNMBXNavigationCarPlaySceneDelegate. The plugin's new carPlay: true option adds the scene entry with that delegate, plus the com.apple.developer.carplay-maps entitlement. It throws if the app has no phone scene, since declaring a scene manifest without one leaves an app-delegate window unshown. Bare apps on RN < 0.88 would first have to adopt scenes themselves. RN 0.88 adds official SceneDelegate support, and Apple requires scenes from the iOS 27 SDK on.
  2. JS. CarPlay has no JS-driven UI. The scene delegate creates the Navigation SDK's CarPlayManager on the process-wide MapboxNavigationProvider that the TurboModule and every navigation map already share, so route handles and the session are reused as they are. While idle, CarPlay shows the SDK's map and free drive (its default). When the phone starts active guidance, CarPlay opens CarPlayNavigationViewController for the same routes. When the phone stops, CarPlay exits it, and ending the trip on CarPlay stops navigation. The only new JS API is Navigation.isCarPlayConnected() and addCarPlayConnectionListener; Android returns false. CarPlay can launch the app without the phone scene, so without React Native; the scene delegate then creates the provider from the Info.plist MBXAccessToken, and JS reuses it later. Without that key CarPlay waits for setAccessToken.
  3. Community libraries. react-native-carplay (birkir, last release 2024, no New Architecture, no Expo) and its fork @g4rb4g3/react-native-carplay (archived in Feb 2026) build CPTemplates from JS and render a React root view into the CPWindow. @iternio/react-native-auto-play is the maintained one. It is New Architecture only, but built on Nitro, has no Expo config plugin, and needs Xcode 27. All of them would re-implement the map and guidance UI that MapboxNavigationUIKit already ships for CarPlay, and would add a second scene setup. So this doesn't depend on any of them. Android Auto is out of scope here. The Navigation SDK's Android Auto extension on the same session would be the analogous route later.

What's in it

  • ios/RNMBXNavigationCarPlay.swift: the scene delegate and the session sync described above.
  • Plugin: the carPlay, carPlayRoot and androidAuto options. Turning them off removes what they added on the next prebuild. The audio background mode moved to feat(plugin): add the audio background mode, with a backgroundAudio opt-out #19; until that lands, the Expo example's Simulate asserts in debug builds.
  • Expo example: a "CarPlay" screen that shows the connection state and starts a simulated trip.

Testing

Unit tests, lint and typecheck pass. The Expo example builds for the iOS Simulator (Release) and Android (debug) against @rnmapbox/maps 10.3.15. The CarPlay-only cold launch was checked in the iOS 26.4 Simulator with the shim (see Status).

Running on a device

The carplay-maps entitlement has to be requested from Apple (developer.apple.com/contact/carplay). Apple adds it to the team as a managed capability, which requires a paid Developer Program membership; a free Personal Team can't get it. Device builds, whether connected to a car or to the CarPlay Simulator Mac app, can't be provisioned with the entitlement until Apple grants it. The Xcode Simulator only needs the entitlement key in the entitlements file.

CarMap (experiment)

<CarMap> adds its @rnmapbox/maps children (sources, layers, images) to the car screen's map instead of the phone's. Render it anywhere in the app; on the phone it is a 0×0 host view. Its children can be a function of activity ("browsing" / "navigating"). Native code reports every switch of the car map (CarPlay replaces its map when guidance starts), and <CarMap> remounts by key so the children are added to the new map.

  • iOS: RNMBXNavigationCarPlay tracks the map CarPlayManager shows (didSetup, willPresent, end of navigation) and the rnmbxnavcar:<id> factory hands it to maps.
  • iOS CarPlay root: Navigation.registerCarPlayRoot(Component) registers a component that the CarPlay scene mounts in a React root of its own (zero-size, under the map) while CarPlay is connected. It's opt-in: the plugin's carPlayRoot option hands the app's RCTReactNativeFactory over in AppDelegate.swift, and on a CarPlay-only launch the root starts React Native on it; the phone scene later shares the same host. The root is created once and moved to each CarPlay window. While it's mounted, <CarMap> elsewhere in the app renders nothing, so the same component serves Android Auto and the CarPlay root. The host is still created on demand rather than in didFinishLaunching, so a phone cold start keeps its launch options for Linking.getInitialURL(). The example renders its <CarMap> layers (a ring following the car, POI circles) in both.
  • Android: a MapSurface-backed car map, fed by an Android Auto CarAppService (Car App Library NavigationTemplate + SurfaceCallback) and, in debug builds, a car screen preview overlay. The plugin's androidAuto option adds the service to the manifest.
  • Both use @rnmapbox/maps support for a map view factory handing over a map that lives elsewhere (iOS ownsMapView = false; Android registerExternalMap, map without a MapView, nullable RNMBXMapView.mapView), from feat: let a map view factory hand over a map that lives elsewhere maps#4412, released in 10.3.15. The peer range is now >=10.3.15 <10.4.0, and both examples use 10.3.15.

Status: on Android the car map shows the POI layers and switches style when guidance starts (verified with the debug preview; real Android Auto untested, no head unit).

On iOS, rebased onto Nav SDK 3.33 / Maps 11.33, a CarPlay-only cold launch (phone app not running) now shows the navigation map in the iOS 26.4 Simulator. Two things were in the way:

  1. Nothing created the navigation provider without JS; fixed with the Info.plist token above. With the CarPlay root, JS now starts too, so <CarMap> layers show without opening the phone app (checked with Simulator City Run: one ring following the puck, no duplicates once the phone scene connects).
  2. With Maps 11.23 the CarPlay map stayed transparent: MapView started its display link only from window.windowScene (nil for CPWindow) or a later scene activation. Maps 11.24+ resolves the CarPlay scene in didMoveToWindow, so 11.33 fixes it without a workaround.

The iOS 26.4/26.5 simulators crash CarPlayTemplateUIHost on any CPMapTemplate (Apple bug, see mapbox/mapbox-navigation-ios#4827). scripts/carplay-simulator-shim has a development-only stub that works around it; it isn't part of the package. The README now covers that, the Info.plist token and the entitlement.

Review follow-up

  • CarPlay taking over guidance: CarPlayNavigationViewController always restarts active guidance from leg 0 in viewDidLoad, so CarPlay connecting mid-trip reset a multi-leg trip to its first leg. CarPlay now restores the phone's leg right after, and ends its guidance again if the phone stopped while CarPlay was starting. Checked in the simulator: a 2-leg simulated trip on leg 1 stays on leg 1 when CarPlay connects (without the restore it drops to leg 0). A single progress event with leg 0 still reaches JS in between.
  • Reconnecting CarPlay (display off and on) reuses the one root; checked that the car map then has one <CarMap> with its two sources.
  • Known issue in @rnmapbox/maps 10.3.15: <CarMap> children never appear on the CarPlay guidance map. For a map it doesn't own, maps waits for isStyleLoaded or the next styleLoaded event, but isStyleLoaded also waits for sources, and on the guidance map it's false after the style already loaded. A fix that re-checks on source and style data events makes them appear (verified locally); it needs a maps release.
  • Android Auto follow-ups: NavigationManager (navigationStarted/navigationEnded, onStopNavigation), a release host allowlist instead of hosts_allowlist_sample, clearing setSurfaceCallback in onDestroy, and not adding androidx.car.app and the service to apps without androidAuto.

CarPlay shows the Navigation SDK's CarPlayManager UI for the same session as
the phone: the map while idle and turn-by-turn guidance while guidance runs.
The Expo plugin's carPlay option adds the CarPlay scene and the carplay-maps
entitlement. The plugin now also adds the audio background mode, without
which the SDK asserts in debug builds when guidance starts.
RNMBXNavigationCarMaps hands the car screen's MapSurface to <CarMap>'s
rnmbxnavcar map. RNMBXNavigationCarMapSurface draws that map onto a car
Surface, fed by the Android Auto SurfaceCallback (CarAppService declared
by the plugin's androidAuto option) or, in debug builds, by a SurfaceView
overlay toggled with an adb broadcast.
CarPlay can cold-launch the app with only the CarPlay scene, so JS never
sets the access token. Fall back to the Maps SDK token (Info.plist
MBXAccessToken) to create the navigation provider, which JS then reuses.
…pView

Nav SDK 3.33 moved the CarPlayManagerDelegate defaults this delegate relies on
to the MapboxCarPlayInternal SPI. On Android, maps #4412 now exposes
RNMBXMapView.mapView as optional.
A ring that follows the navigation location and larger POI circles, drawn
with @rnmapbox/maps layers through <CarMap>.
…y launch

Navigation.registerCarPlayRoot registers a component that the CarPlay scene
mounts in a React root of its own while CarPlay is connected, on the app's
React Native factory. When CarPlay launches the app without its phone UI,
that root starts React Native; the phone scene later shares the same host.
The Expo plugin's carPlay option hands the factory to the CarPlay scene in
AppDelegate.swift. The host is still created on demand, so a phone cold start
keeps its launch options for Linking.getInitialURL.

The example renders its car map layers in that root on iOS and keeps them
emissive so the night style doesn't darken them.
<CarMap> uses the map view factory support for maps that live elsewhere
from rnmapbox/maps#4412, released in 10.3.15.
CarPlayNavigationViewController always starts active guidance from leg 0
in viewDidLoad, so CarPlay connecting mid-trip set a multi-leg trip back
to its first leg, and a trip the phone stopped while CarPlay was still
starting came back. Restore the leg index right after the view controller
restarts guidance, and end CarPlay's guidance again if the phone stopped
meanwhile.
Reconnecting CarPlay created a second root while the first one's surface
could still run, mounting <CarMap> twice on the same map. The root is now
created once and moved to each new CarPlay window.

An Objective-C helper creates it with React Native's own root view API,
with a fallback for versions before 0.84, instead of key-value lookups
and an unsafe cast; the factory property is typed.

The provider sink waits until the session has set its provider, and
setting a different token after CarPlay created the provider logs a
warning instead of being ignored silently.
The CarPlay root wraps the registered component in a context. While it
is mounted, <CarMap> elsewhere in the app renders nothing, so the same
component can be rendered in the app for Android Auto and registered as
the CarPlay root without duplicating layers on iOS.

The plugin hands the factory to CarPlay only with carPlayRoot: true, so
apps that use the stock CarPlay UI don't start React Native on a
CarPlay-only launch. It warns instead of failing the prebuild for an app
delegate it doesn't know, and removes its scene, app delegate lines and
Android Auto service when the options are turned off. The audio
background mode moves to its own change.

CAR_MAP_VIEW_IMPL and the car event types are no longer exported.
It moves to the library's debug source set, with a no-op in release. Its
receiver is registered once and uses the latest React context, so it
keeps working after a JS reload instead of holding on to the first one.
@mfazekas
mfazekas marked this pull request as ready for review October 27, 2026 20:39
@mfazekas
mfazekas merged commit f4bf4c2 into main Oct 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant