- iOS 12.0+
- Xcode 10.2+
Coastal Roads is a sample navigation app that demonstrates how to display a custom map and navigation instructions from a CarPlay–enabled vehicle. Coastal Roads integrates with the CarPlay framework by implementing the map and additional
CPTemplate subclasses, such as
CPList. This sample’s iOS app component provides a logging interface to help you understand the life cycle of a CarPlay app.
Configure the Sample Code Project
CarPlay navigation apps require a CarPlay navigation entitlement. For more information, see Adding CarPlay Support to Your Navigation App. (Alternatively, you can request the entitlement here). Once the entitlement is granted:
Log in to your account on the Apple Developer website and create a new provisioning profile that includes the CarPlay navigation app entitlement.
Import the newly created provisioning profile into Xcode.
Entitlementsfile in your project, if you don’t have one already.
Create a key for the CarPlay navigation app entitlement as a Boolean. Make sure that your target project setting
CODEis set to the path of your
For more information about configuring projects for CarPlay, see Adding CarPlay Support to Your Navigation App.
Handle Communication with CarPlay
Implement the following methods on
CPApplication to handle tasks during various points in the app’s life cycle:
You’re also responsible for adding and removing the root view controller of your CarPlay window in response to connections and disconnections.
The following code shows an example implementation of setting a root template:
Render a Map as Your Base Template
The sample includes an image to serve as the map. In your app, you’ll use your own map or image to serve as the base template. The base template must be an instance of
CPMap with no additional graphics or UI elements. All overlays should be of a template type that is provided by CarPlay. Your map template can use trait collections to handle size classes programmatically. Your map must cover the entire screen, which you can accomplish by using constraints.