I'm developing a CarPlay music app and encountering a crash when trying to present a CPActionSheetTemplate using presentTemplate on the CPInterfaceController in iOS 15.5. The app functions as expected on iOS 17*. Here is code which I'm using to present action sheet:
func showRequestSheet(_ id:String) {
appPrint("Category Clicked: ", id)
let actDismiss = CPAlertAction(title: "Dismiss", style: .destructive, handler: { action in
self.interfaceController?.dismissTemplate(animated: true, completion: nil)
})
let actOk = CPAlertAction(title: "ok".translated, style: .default, handler: { action in
if let category = CPHelper.shared.arrCategories.first(where: {return $0.id == id}) {
self.interfaceController?.dismissTemplate(animated: true, completion: nil)
CPHelper.shared.requestAudioAPI(category.name) { (isSuccess, error) in
if let err = error {
let actDone = CPAlertAction(title: "e-mail_registration_password-strength-ok".translated, style: .default, handler: { action in
self.interfaceController?.dismissTemplate(animated: true, completion: nil)
})
let alert = CPAlertTemplate(titleVariants: [err.translated], actions: [actDone])
self.interfaceController?.presentTemplate(alert, animated: true, completion: { isSuccess, error in
if let err = error {
appPrint("Category Success presentTemplate error: ", err)
}
})
}
}
}
})
let actionSheet = CPActionSheetTemplate(title: "auto_app_request-audio-carplay-title".translated, message: "auto_app_request-audio-carplay-text".translated, actions: [actOk,actDismiss])
interfaceController?.presentTemplate(actionSheet, animated: true, completion: { isSuccess, error in
if let err = error {
appPrint("Category presentTemplate error: ", err)
}
})
}
Crashing with below errror in iOS 15.5:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported object <CPActionSheetTemplate: 0x600000883720> <identifier: 154853B1-42C9-4A2E-A2AA-8431664FCDC4, userInfo: (null), tabTitle: (null), tabImage: (null), showsTabBadge: 0> passed to presentTemplate:animated:completion:. Allowed classes: {(
CPGridTemplate,
CPListTemplate,
CPNowPlayingTemplate,
CPTabBarTemplate,
CPAlertTemplate,
CPVoiceControlTemplate
)}
Attaching screenshot which show me availability of actionsheet here:
Thanks in advance!
It should be presented
That's because you are using unsupported object on presentTemplate method in CPInterfaceController type CPActionSheetTemplate. https://developer.apple.com/carplay/documentation/CarPlay-App-Programming-Guide.pdf You have to use something from this list instead: CPGridTemplate, CPListTemplate, CPNowPlayingTemplate, CPTabBarTemplate, CPAlertTemplate, CPVoiceControlTemplate