I am creating a turn-by-turn navigation app for CarPlay. I have two shortcut buttons on the dashboard view. When tapping one of the buttons, I expect the screen to transition into the "main" app. However, what happens is: It runs the code behind the scenes (search for either food or fuel) and it displays the search results, but you can only see them if you manually tap on the map or the app icon.
My code looks like this:
func initializeDashboardButtons() {
if let image1 = UIImage(systemName: "fuelpump"), let image2 = UIImage(systemName: "fork.knife") {
let button1 = CPDashboardButton(titleVariants: [defaultFuel], subtitleVariants: [], image: image1, handler: { [weak self] _ in self?.navigateToGasStations() })
let button2 = CPDashboardButton(titleVariants: [defaultFood], subtitleVariants: [], image: image2, handler: { [weak self] _ in self?.navigateToFood() })
self.dashboardController?.shortcutButtons = [button1, button2]
}
}
private func navigateToGasStations() {
self.carplayManager.searchForLocation(locationText: defaultFuel, completionHandler: { [weak self] destinations in self?.handleSearchResult(results: destinations) })
}
private func navigateToFood() {
self.carplayManager.searchForLocation(locationText: defaultFood, completionHandler: { [weak self] destinations in self?.handleSearchResult(results: destinations) })
}
private func handleSearchResult(results: [Destination]) {
self.defaultAction?(results.convertToCPListItem(), "")
}
My goal is to open the main app, when one of the two buttons it tapped.
Thanks in advance.
I have tried to look at Apples sample app, where they also have shortcut buttons. However their sample app does not transition into the main app either. I can see that Google can do it with their Maps app, so there must be a way. I just haven't found it in the documentation.
I also looked at this question/answer, but it does not work for me. How to launch app in CarPlay Dashboard after click CPDashboardButton in CPDashboardController