Hello,
Could you please help me with the below,
How to display a toast message to the user in CarPlay after a successful operation?
How to show a spinner or an activity indicator just before performing some operation?
I have referred to the CarPlay pdf design guidelines in which I couldn't find support for the above two. But I could see a loader within a button in one of the default apps in CarPlay simulator.
Kindly help me with these queries
Post
Replies
Boosts
Views
Activity
Hello,
Please guide me if there is a way to show a simple toast to a user that the action has been performed. When a user taps on a button, an api returns a status based on which I need to show appropriate message as a toast. Is this possible in CarPlay? If not, why? Please suggest any alternative for this.
Awaiting your response
Thanks a lot!!
I am developing a CarPlay app, that has been approved for EV Charging entitlement. Could you please confirm if the given entitlement supports CPSearchTemplate template as there is some confusion here.
I tried using the template by referring to the below link,
https://developer.apple.com/documentation/carplay/cpsearchtemplate
Here is the snippet,
class SearchCPView: UIResponder, CPSearchTemplateDelegate {
var searchTemplate: CPSearchTemplate = CPSearchTemplate()
override init() {
super.init()
searchTemplate.delegate = self
}
func getSearchTemplate(interfaceController: CPInterfaceController?) -> CPGridTemplate {
let searchGridButton = CPGridButton(titleVariants: [CarplayButtonTitles.search], image: UIImage(named: ImagesConstants.CarPlay.searchGrid) ?? UIImage(), handler: {[self] _ in
guard let controller = interfaceController else { return }
controller.pushTemplate(self.searchTemplate, animated: true) { status, error in
print(status)
}
})
let gridTemplate = CPGridTemplate(title: "", gridButtons: [searchGridButton])
return gridTemplate
}
func searchTemplate(_ searchTemplate: CPSearchTemplate, selectedResult item: CPListItem) async {
print(item)
}
func searchTemplate(_ searchTemplate: CPSearchTemplate, updatedSearchText searchText: String) async -> [CPListItem] {
print(searchText)
return [CPListItem(text: "", detailText: "")]
}
}
On push, I am getting an exception,
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported object <CPSearchTemplate: 0x30056df00> <identifier: 28, userInfo: (null), tabTitle: (null), tabImage: (null), showsTabBadge: 0> passed to pushTemplate:animated:completion:. Allowed classes: {(
CPTabBarTemplate,
CPActionSheetTemplate,
CPAlertTemplate,
CPGridTemplate,
CPPointOfInterestTemplate,
CPInformationTemplate,
CPContactTemplate,
CPListTemplate
)}'
I have developed a mobile app using SwiftUI. Now I am in the process of building a CarPlay application. I know how to test the CarPlay app using a simulator but here is my confusion,
Testing the iPhone app and CarPlay together (few scenarios like user login / logout, location enabled /disabled in the mobile app)
Kindly help me validate the above scenarios as I am getting black screen on iPhone whenever the CarPlay is launched. Below is the code snippet,
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
if connectingSceneSession.role == .carTemplateApplication {
let sceneConfiguration = UISceneConfiguration(name: "CarPlay Scene", sessionRole: connectingSceneSession.role)
sceneConfiguration.delegateClass = CarPlaySceneDelegate.self
return sceneConfiguration
}
// Configuration for other types of scenes
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
.preferredColorScheme(.light)
}
}
}
Info.plist
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>CPTemplateApplicationSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>CarPlay Scene</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).CarPlaySceneDelegate</string>
</dict>
</array>
</dict>
</dict>
I have developed a mobile app using SwiftUI. Now I am in the process of building a CarPlay application. I know how to test the CarPlay app using a simulator but here is my confusion,
How to test the iPhone app and CarPlay together? I want to test few scenarios like, user login / logout from mobile app. Location enabled /disabled in the mobile app.
I know that swiftUI handles the scenes by itself. Kindly help me validate the above scenarios as I am getting black screen on iPhone whenever the CarPlay is launched. Below is the code snippet,
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
if connectingSceneSession.role == .carTemplateApplication {
let sceneConfiguration = UISceneConfiguration(name: "CarPlay Scene", sessionRole: connectingSceneSession.role)
sceneConfiguration.delegateClass = CarPlaySceneDelegate.self
return sceneConfiguration
}
// Configuration for other types of scenes
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
.preferredColorScheme(.light)
}
}
}
Info.plist
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>CPTemplateApplicationSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>CarPlay Scene</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).CarPlaySceneDelegate</string>
</dict>
</array>
</dict>
</dict>
I have developed a mobile app using SwiftUI that supports GoogleMaps. Now I am in the process of building a CarPlay application. I assume CarPlay only supports Apple MapKit, as I could not find any way to integrate the Google Maps. Below are few queries,
Could you please guide me on how I can obtain the user's current location on the CarPlay app launch? Is there a way CarPlay can get the details from the mobile app(not pretty sure as its using Google Maps)?
If the user is logged out from the mobile app, what is the flow in CarPlay? Do we have any standard login page asking user to login to the mobile app first?
Is there any UI asking the user to capture the location in CarPlay?
This is my first CarPlay app. Kindly guide me to a document or so that covers these details.
Thanks a ton!!
I am new to CarPlay development. I am working on an app that has four tabs. The first tab has a POI template. I make an API call, once the data is received, I need to refresh the POI template to display the data received. Below is a sample code. Please guide me on this. Right now I am pushing a new template once data is obtained which is not the right behaviour
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
self.interfaceController = interfaceController
let tabs = CPTabBarTemplate(templates: [firstTab(), secondTab(), thirdTab(), fourthTab()])
interfaceController.setRootTemplate(tabs,
animated: true,
completion: nil)
}
func firstTab() -> CPTemplate {
// Placeholder template while data is loading
let placeholderPOI = CPPointOfInterest(location: MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0))),
title: "Loading...",
subtitle: "",
summary: "Data is currently loading",
detailTitle: "",
detailSubtitle: "",
detailSummary: "",
pinImage: nil)
let placeholderTemplate = CPPointOfInterestTemplate(title: "EV Stations", pointsOfInterest: [placeholderPOI], selectedIndex: 0)
// Asynchronously update the template once data is loaded
Task {
await loadAndUpdateTimeConsumingData(for: placeholderTemplate)
}
return placeholderTemplate
}
func loadAndUpdateTimeConsumingData(for template: CPPointOfInterestTemplate) async {
do {
// Simulate a 1-minute delay
try await Task.sleep(nanoseconds: 60 * 1_000_000_000)
// Mock data
let stations = [Station1(name: "Station 1", city: "City A", address: "123 Lane", coordinates: (latitude: 12.3456, longitude: 76.7890))]
let pointsOfInterest = stations.map { station -> CPPointOfInterest in
let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: station.coordinates.latitude, longitude: station.coordinates.longitude)))
return CPPointOfInterest(location: mapItem,
title: station.name,
subtitle: station.city,
summary: station.address,
detailTitle: "",
detailSubtitle: "",
detailSummary: "",
pinImage: nil)
}
// Update the template
let poiTemplate = CPPointOfInterestTemplate(title: "EV Stations", pointsOfInterest: pointsOfInterest, selectedIndex: 0)
await MainActor.run {
self.interfaceController?.pushTemplate(poiTemplate, animated: true, completion: nil)
}
} catch {
}
}
In Carplay, is it possible to update the navigation title and also add right tab bar items? Couldn't find these details in the documentation. Please suggest
I have a SwiftUI app, and Apple has approved the Carplay entitlement. The entitlement integration is done successfully, however when I try to launch the carplay app I get the below error
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Application does not implement CarPlay template application lifecycle methods in its scene delegate.'
Info.plist:
UIApplicationSceneManifest
UIApplicationSupportsMultipleScenes
UISceneConfigurations
CPTemplateApplicationSceneSessionRoleApplication
UISceneConfigurationName
Default Configuration
UISceneDelegateClassName
$(PRODUCT_MODULE_NAME).CarPlaySceneDelegate
In AppDelegate I have the below
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
if connectingSceneSession.role == .carTemplateApplication {
let sceneConfiguration = UISceneConfiguration(name: "CarPlay Scene", sessionRole: connectingSceneSession.role)
sceneConfiguration.delegateClass = CarPlaySceneDelegate.self
return sceneConfiguration
}
// Configuration for other types of scenes
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
Why am I getting the exception? Kindly suggest
Following is a row item within a section of CPListTemplate,
CPListItem(text: "Station 1", detailText: "Details\nforStation 1")
In the above, is it possible to display data in three lines? I have seen couple of CarPlay apps that do it within a list. However, I am not sure how this can be done. Kindly suggest some ideas
Currently I have the below,
I want to achieve the below, three lines with a row
I have a list of items/cells where each item has many elements within it including a button. On tap of a cell, it navigates to screen say ViewA. And on tap of button within the cell, it goes to ViewB. However, on tap of the cell, instead of navigating to ViewA, it randomly navigates to ViewB even though the nav link isActive is disabled. Please suggest!
ViewA - List view
`List {
ForEach(testData, id: \.self) { index in
ZStack {
NavigationLink("", destination:ViewA()).opacity(0)
ViewAListItem()
}.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.background(.clear)
}
}`
In another file,
struct ViewAListItem: View {
@State var test: Bool = false
/// some other code
///
///
///
Button(action: {
test = true
}) {
Text("Testing")
}.background(
NavigationLink("", destination: ViewB(), isActive: $test).opacity(0)
)
}
Here even though the button is not tapped, variable test is true and navigating to ViewB on tap of cell which should launch ViewAListItem instead. Any issue with this?