Class

CPInterfaceController

A controller that manages the templates that provide the user interface for your app on the CarPlay screen.

Declaration

class CPInterfaceController : NSObject

Overview

An interface controller manages one or more templates in the navigation hierarchy. You don’t create the interface controller. Instead, the system creates it for you, and passes the controller to your app by way of the CPApplicationDelegate method application(_:didConnectCarInterfaceController:to:). For more information, see Adding CarPlay Support to Your Navigation App.

After receiving the controller, store a reference to it in your app. Then set the root template by calling the setRootTemplate(_:animated:) method. To display another template in the navigation hierarchy, call pushTemplate(_:animated:), and use popTemplate(animated:) to remove the top-most template.

You also use the interface controller to display a single template modally. Call presentTemplate(_:animated:) to display the modal template, and call dismissTemplate(animated:) to dismiss it.

Topics

Configuring the Interface Controller

func setRootTemplate(CPTemplate, animated: Bool)

Sets the root template, starting a new stack for the template navigation hierarchy.

var delegate: CPInterfaceControllerDelegate?

An object serving as the delegate to the interface controller.

protocol CPInterfaceControllerDelegate

The interface that an object implements to serve as a delegate to an interface controller.

Accessing Templates on the Navigation Stack

var rootTemplate: CPTemplate

The current root template in the template navigation hierarchy.

var topTemplate: CPTemplate?

The top-most template in the navigation hierarchy stack.

var templates: [CPTemplate]

The current stack of templates in the navigation hierarchy.

Pushing and Popping Templates

func pushTemplate(CPTemplate, animated: Bool)

Pushes a template onto the navigation stack and updates the CarPlay display.

func popTemplate(animated: Bool)

Pops the top template from the navigation stack and updates the CarPlay display.

func popToRootTemplate(animated: Bool)

Pops all templates on the stack—except the root template—and updates the CarPlay display.

func pop(to: CPTemplate, animated: Bool)

Pops templates until the specified template is at the top of the navigation stack.

Displaying Templates Modally

func dismissTemplate(animated: Bool)

Dismisses the template that the interface controller is displaying modally.

var presentedTemplate: CPTemplate?

The current modal template displayed by the interface controller.

Relationships

Inherits From

Conforms To

See Also

User Interface Basics

class CPMapTemplate

A template that provides a navigation bar and map buttons allowing users to interact with your app.

class CPListTemplate

A template that displays a hierarchical list of items.

class CPGridTemplate

A template that displays a grid of items.

class CPTemplate

An abstract base class for interface templates.

class CPImageSet

Light and dark representations of an image.