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>
Your app is specifying a scene delegate class named CarPlaySceneDelegate
, but you haven't shared any implementation for that class. Does that class exist? It will also need to implement the CPTemplateApplicationSceneDelegate
protocol, and it should receive and store a reference to the CPInterfaceController
that manages the lifecycle of templates for your app. That's also where you present templates, and if your app isn't presenting any templates, that would explain why you're seeing a black screen.
How to test the iPhone app and CarPlay together? I want to test few scenarios like, user login / logout from mobile app
CarPlay runs in the same app, in the same process, as your phone app. You should test by logging out in the phone app on device while connected to the CarPlay simulator.
Location enabled /disabled in the mobile app.
Try granting (or revoking) location permissions for your iOS app in iOS preferences.
I know that swiftUI handles the scenes by itself.
Only on iOS. In CarPlay, your app is responsible for presenting templates and managing their lifecycle, by using CPInterfaceController
. Please see the CarPlay documentation for more details: https://developer.apple.com/documentation/carplay/cpinterfacecontroller