Hi everyone,
I'm developing a CarPlay application and using a CPTabBarTemplate to display multiple tabs. I want to determine which tab is selected when the user clicks on a tab, specifically when switching to the second tab.
Here’s the relevant part of my code:
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
var interfaceController: CPInterfaceController?
var tabBarTemplate: CPTabBarTemplate = CPTabBarTemplate(templates: [])
func templateApplicationScene(
_ templateApplicationScene: CPTemplateApplicationScene,
didConnect interfaceController: CPInterfaceController
) {
self.interfaceController = interfaceController
// Create and set the TabBarTemplate
let tabBarTemplate = createTabBarTemplate()
self.tabBarTemplate = tabBarTemplate
interfaceController.setRootTemplate(tabBarTemplate, animated: false) { success, error in
if let error = error {
print("Error setting TabBarTemplate: \(error.localizedDescription)")
} else {
print("TabBarTemplate set successfully.")
}
}
}
func createTabBarTemplate() -> CPTabBarTemplate {
let listItem1 = CPListItem(text: "Item 1", detailText: "Detail 1")
let listItem2 = CPListItem(text: "Item 2", detailText: "Detail 2")
let listTemplate = CPListTemplate(
title: "List",
sections: [CPListSection(items: [listItem1, listItem2])]
)
let gridButton1 = CPGridButton(
titleVariants: ["Grid 1"],
image: UIImage(systemName: "star.fill")!
)
let gridButton2 = CPGridButton(
titleVariants: ["Grid 2"],
image: UIImage(systemName: "star")!
)
let gridTemplate = CPGridTemplate(
title: "Grid",
gridButtons: [gridButton1, gridButton2]
)
return CPTabBarTemplate(templates: [listTemplate, gridTemplate])
}
}
Post
Replies
Boosts
Views
Activity
I’m currently developing an app that communicates with a BLE dongle. When I swipe up to close the app on my phone, both the phone app and the CarPlay app are terminated. From the CarPlay interface, I can relaunch the app. My question is: Can CarPlay establish a connection with a BLE dongle when the phone app is fully closed or not running in the background?
Is it possible to disable user interaction for items in a CarPlay template? Based on my research, it seems that touch interaction is controlled by the system UI, and there isn't an API available to disable it.
Hi everyone,
I'm working with the CarPlay TabBar template in my app. Is there a way to programmatically switch between tabs, or is this only possible through user interaction?
Any guidance or clarification would be appreciated. Thanks!
Hi everyone,
I'm working with the CarPlay TabBar template in my app. Is there a way to programmatically switch between tabs, or is this only possible through user interaction?
Any guidance or clarification would be appreciated. Thanks!
Currently, when on the phone, like Spotify, I fully close the Spotify app, and in Carplay, when the user clicks on the Spotify app, this app can open as normal. I also developed my app but when I open the app in carplay, it shows a white screen, and then the app auto-terminates (closes permanently). How Can I do the behavior like the Spotify app, My app also enabled background mode in xCode. Please help me. Thanks so much
I'm woking on CarPlay app. Recently when I fully closed my app on ios phone it also close the Carplay app. So is there any solution to show the alert to users know that you have to open the app to use these features in carplay. The message I want to show it in carpla