How to show alert to CarPlay

I am developing a CarPlay app to provide CarPlay services in music apps.

I do not know how to play an alert when CarPlay is not playing music.


If you look at the Human Interface Guidelines provided by the Apple developer site, you are told to use a UIAlertController, but I do not know how to do a UIAlertController with presentViewController.

(- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion)


How can I show an alert to CarPlay?


<CarPlay Human Interface Guidelines>

Alerts convey important information related to the state of your app. An alert consists of a title, an optional message, and one or more buttons. Aside from these configurable elements, the visual appearance of an alert is static and can’t be customized.


Minimize alerts. Alerts disrupt the user experience. Use alerts only for important situations like notifying people about problems. The infrequency of alerts helps ensure that people take them seriously.

For developer guidance, see UIAlertController.

Hi,


Here is an example of standard use :


UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];

// customize you alertController with UIAlertAction instances

[self presentViewController:alertController animated:YES completion:nil];


CarPlay doesn't explicitly provide a UIViewController for you to work with, however you can use the completion handler of the following methods :

https://developer.apple.com/documentation/mediaplayer/mpplayablecontentdelegate/1648205-playablecontentmanager

https://developer.apple.com/documentation/mediaplayer/mpplayablecontentdelegate/1620292-playablecontentmanager

https://developer.apple.com/documentation/mediaplayer/mpplayablecontentdatasource/1649672-contentitem

https://developer.apple.com/documentation/mediaplayer/mpplayablecontentdatasource/1619508-beginloadingchilditems

To pass any error objects you want to display to the user.


Hopefully this helps :-)

Hi Rico,


how we can show errors, for example playing a audio stream, when the connection get lost?
On my Example i passed already the completion handler because its loaded and its a continious stream.

Still not answered how to display an alert on an error in Carplay? Anyone?

Hello @OHSEUNGWOOK and @batistuta,

I believe you can present alerts in a CarPlay app using CPAlertTemplate.

I hope this helps.

Best regards,

How to show alert to CarPlay
 
 
Q