Basis of CarPlay framework — First Step — How to compile your first CarPlay App

Jordan Montel
3 min readJul 14, 2021

Playing with basis of CarPlay.framework and Template is the goal here without spend a lot of time of research in documentation and internet!

If you want to build your first CarPlay app with Templates you are in the right place !

Let’s go to start with the initial configuration to compile a first CarPlay app step by step !

Let’s dive directly inside Xcode !

Firstly, create a new Xcode Project iOS App using Storyboard, UIKit App Delegate and Swift.

This project must adopt scenes ! (page 24/49 of the official Apple Documentation).

Create Xcode project
Create Xcode project

CarPlay Entitlement

Your project need an entitlement to select the good feature of your application (page 8 and 9/49 of the official Apple Documentation).

Here we will use com.apple.developer.carplay-audio.

Step to create entitlement :

  1. File > New > File > Property List > Next
  2. Save As CarPlayTutorial.entitlements > Create
  3. Update your Project > Build Settings > Code Signing Entitlements > CarPlayTutorial/CarPlayTutorial.entitlements
  4. Set the entitlement com.apple.developer.carplay-audio > Boolean > YES
Build Settings
Build Settings
Carplay Audio Entitlement
CarPlay Audio Entitlement

Create Car Play Scene

  1. File > New > File > Swift File > CarPlaySceneDelegate
  2. import CarPlay
  3. Implements UIResponder and CPTemplateApplicationSceneDelegate
  4. Add a List Template
CarPlaySceneDelegate
CarPlaySceneDelegate
import CarPlay
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
var interfaceController: CPInterfaceController?
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
self.interfaceController = interfaceController
// Create a list
let item = CPListItem(text: "title", detailText: "detail")
item.accessoryType = .disclosureIndicator
let section = CPListSection(items: [item])
let listTemplate = CPListTemplate(title: "Section", sections: [section])
// Set root
self.interfaceController?.setRootTemplate(listTemplate, animated: true, completion: {_, _ in })
}
// CarPlay disconnected
private func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didDisconnect interfaceController: CPInterfaceController) {
self.interfaceController = nil
}
}

Update Application Scene Manifest

  1. Open Info.plist
  2. Application Scene Manifest >Enable Multiple Windows > YES
  3. Open Application Scene Manifest > Scene Configuration
  4. Add External Display Session Role
  5. Class Name > CPTemplateApplicationScene (name of the protocol implemented for CarPlay)
  6. Delegate Class Name > $(PRODUCT_MODULE_NAME).CarPlaySceneDelegate (CarPlay’s scene delegate)
  7. Configuration Name > CarPlay (unique string to identify the configuration)
  8. Remove Storyboard Name
Info.plist CarPlay Scene Configuration
Info.plist CarPlay Scene Configuration

Update AppDelegate

Set the connectionSceneSession depending of iOS or CarPlay.

AppDelegate Scenes
AppDelegate Scenes
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {        
if (connectingSceneSession.role == UISceneSession.Role.carTemplateApplication) {
let scene = UISceneConfiguration(name: "CarPlay", sessionRole: connectingSceneSession.role)
scene.delegateClass = CarPlaySceneDelegate.self
return scene
} else {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
}

Run !

You can now compile your project eg. on iPhone 12 and open the CarPlay simulator !

Simulator > I/O > External Displays > CarPlay

Open CarPlay simulator
Open CarPlay simulator

And the result :

CarPlay App
CarPlay App

To go deeper…

Here you have learn how to compile a first CarPlay App using CarPlay.framework.

The code is available here tag 1.0.0 : https://github.com/T0yBoy/CarPlayTutorial/tree/1.0.0

Next tutorial will talk about how to use Templates !

It was my first article so do not hesitate if you have some questions or if you want that I go further in other part of CarPlay.framework !

Have fun !

External Documentation

https://developer.apple.com/carplay/documentation/CarPlay-App-Programming-Guide.pdf

--

--