CarPlayManagerDelegate

@objc(MBCarPlayManagerDelegate)
public protocol CarPlayManagerDelegate

CarPlayManagerDelegate is the main integration point for Mapbox CarPlay support.

Implement this protocol and assign an instance to the delegate property of the shared instance of CarPlayManager.

  • Offers the delegate an opportunity to provide a customized list of leading bar buttons at the root of the template stack for the given activity.

    These buttons’ tap handlers encapsulate the action to be taken, so it is up to the developer to ensure the hierarchy of templates is adequately navigable.

    Declaration

    Swift

    @objc(carPlayManager:leadingNavigationBarButtonsWithTraitCollection:inTemplate:forActivity:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, leadingNavigationBarButtonsCompatibleWith traitCollection: UITraitCollection, in template: CPTemplate, for activity: CarPlayActivity) -> [CPBarButton]?

    Parameters

    carPlayManager

    The shared CarPlay manager.

    traitCollection

    The trait collection of the view controller being shown in the CarPlay window.

    template

    The template into which the returned bar buttons will be inserted.

    activity

    What the user is currently doing on the CarPlay screen. Use this parameter to distinguish between multiple templates of the same kind, such as multiple CPMapTemplates.

    Return Value

    An array of bar buttons to display on the leading side of the navigation bar while template is visible.

  • Offers the delegate an opportunity to provide a customized list of trailing bar buttons at the root of the template stack for the given activity.

    These buttons’ tap handlers encapsulate the action to be taken, so it is up to the developer to ensure the hierarchy of templates is adequately navigable.

    Declaration

    Swift

    @objc(carPlayManager:trailingNavigationBarButtonsWithTraitCollection:inTemplate:forActivity:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, trailingNavigationBarButtonsCompatibleWith traitCollection: UITraitCollection, in template: CPTemplate, for activity: CarPlayActivity) -> [CPBarButton]?

    Parameters

    carPlayManager

    The shared CarPlay manager.

    traitCollection

    The trait collection of the view controller being shown in the CarPlay window.

    template

    The template into which the returned bar buttons will be inserted.

    activity

    What the user is currently doing on the CarPlay screen. Use this parameter to distinguish between multiple templates of the same kind, such as multiple CPMapTemplates.

    Return Value

    An array of bar buttons to display on the trailing side of the navigation bar while template is visible.

  • Offers the delegate an opportunity to provide a customized list of buttons displayed on the map.

    These buttons handle the gestures on the map view, so it is up to the developer to ensure the map template is interactive. If this method is not implemented, or if nil is returned, a default set of zoom and pan buttons declared in the CarPlayMapViewController will be provided.

    Declaration

    Swift

    @objc(carPlayManager:mapButtonsCompatibleWithTraitCollection:inTemplate:forActivity:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, mapButtonsCompatibleWith traitCollection: UITraitCollection, in template: CPTemplate, for activity: CarPlayActivity) -> [CPMapButton]?

    Parameters

    carPlayManager

    The shared CarPlay manager.

    traitCollection

    The trait collection of the view controller being shown in the CarPlay window.

    template

    The template into which the returned map buttons will be inserted.

    activity

    What the user is currently doing on the CarPlay screen. Use this parameter to distinguish between multiple templates of the same kind, such as multiple CPMapTemplates.

    Return Value

    An array of map buttons to display on the map while template is visible.

  • Offers the delegate an opportunity to provide an alternate navigation service, otherwise a default built-in MapboxNavigationService will be created and used.

    Declaration

    Swift

    @objc(carPlayManager:navigationServiceAlongRoute:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, navigationServiceAlong route: Route) -> NavigationService

    Parameters

    carPlayManager

    The shared CarPlay manager.

    route

    The route for which the returned route controller will manage location updates.

    Return Value

    A navigation service that manages location updates along route.

  • Offers the delegate an opportunity to react to updates in the search text.

    Postcondition

    You must call completionHandler within this method.

    Declaration

    Swift

    @objc(carPlayManager:searchTemplate:updatedSearchText:completionHandler:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, searchTemplate: CPSearchTemplate, updatedSearchText searchText: String, completionHandler: @escaping ([CPListItem]) -> Void)

    Parameters

    carPlayManager

    The shared CarPlay manager.

    searchTemplate

    The search template currently accepting user input.

    searchText

    The updated search text in searchTemplate.

    completionHandler

    Called when the search is complete. Accepts a list of search results.

  • Offers the delegate an opportunity to react to selection of a search result.

    Postcondition

    You must call completionHandler within this method.

    Declaration

    Swift

    @objc(carPlayManager:searchTemplate:selectedResult:completionHandler:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, searchTemplate: CPSearchTemplate, selectedResult item: CPListItem, completionHandler: @escaping () -> Void)

    Parameters

    carPlayManager

    The shared CarPlay manager.

    searchTemplate

    The search template currently accepting user input.

    item

    The search result the user has selected.

    completionHandler

    Called when the delegate is done responding to the selection.

  • Offers the delegate the opportunity to customize a trip before it is presented to the user to preview.

    Declaration

    Swift

    @objc(carPlayManager:willPreviewTrip:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip) -> (CPTrip)

    Parameters

    carPlayManager

    The shared CarPlay manager.

    trip

    The trip that will be previewed.

    Return Value

    The actual trip to be previewed. This can be the same trip or a new/alternate trip if desired.

  • Offers the delegate the opportunity to customize a trip preview text configuration for a given trip.

    Declaration

    Swift

    @objc(carPlayManager:willPreviewTrip:withPreviewTextConfiguration:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip, with previewTextConfiguration: CPTripPreviewTextConfiguration) -> (CPTripPreviewTextConfiguration)

    Parameters

    carPlayManager

    The shared CarPlay manager.

    trip

    The trip that will be previewed.

    previewTextConfiguration

    The trip preview text configuration that will be presented alongside the trip.

    Return Value

    The actual preview text configuration to be presented alongside the trip.

  • Offers the delegate the opportunity to react to selection of a trip. Certain trips may have alternate route(s).

    Declaration

    Swift

    @objc(carPlayManager:selectedPreviewForTrip:usingRouteChoice:)
    optional func carPlayManager(_ carPlayManager: CarPlayManager, selectedPreviewFor trip: CPTrip, using routeChoice: CPRouteChoice)

    Parameters

    carPlayManager

    The shared CarPlay manager.

    trip

    The trip to begin navigating along.

    routeChoice

    The possible route for the chosen trip.

  • Called when navigation begins so that the containing app can update accordingly.

    Declaration

    Swift

    @objc(carPlayManager:didBeginNavigationWithNavigationService:)
    func carPlayManager(_ carPlayManager: CarPlayManager, didBeginNavigationWith service: NavigationService)

    Parameters

    carPlayManager

    The shared CarPlay manager.

    service

    The navigation service that has begun managing location updates for a navigation session.

  • Called when navigation ends so that the containing app can update accordingly.

    Declaration

    Swift

    @objc
    func carPlayManagerDidEndNavigation(_ carPlayManager: CarPlayManager)

    Parameters

    carPlayManager

    The shared CarPlay manager.

  • Called when the carplay manager will disable the idle timer.

    Implementing this method will allow developers to change whether idle timer is disabled when carplay is connected and the vice-versa when disconnected.

    Declaration

    Swift

    @objc
    optional func carplayManagerShouldDisableIdleTimer(_ carPlayManager: CarPlayManager) -> Bool

    Parameters

    carPlayManager

    The shared CarPlay manager.

    Return Value

    A Boolean value indicating whether to disable idle timer when carplay is connected and enable when disconnected.