0

I am developing an iOS app that includes CarPlay usage. I have added the CarPlay entitlements given by apple to my app and when I launch the app it is shown in the CarPlay simulator as well, however when I run it I get the "Unable to connect to app" error screen. I have implemented the AppDelegate configurationForConnecting callback as instructed and added my CarPlay scene configuration in the info.plist

AppDelegate

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        print(connectingSceneSession.role)
        if(connectingSceneSession.role == UISceneSession.Role.carTemplateApplication) {
            let scene =  UISceneConfiguration(name: "CarPlay", sessionRole: connectingSceneSession.role)
            return scene
        } else {
            let scene =  UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
            return scene
        }
    }

Info.plist (One of many combinations I tried)

enter image description here

However when I run the app the configurationForConnecting is only called once and only for UIWindowSceneSessionRoleApplication but It is never called for UISceneSession.Role.carTemplateApplication. Interestingly if I also open an external display in the simulator I do get the UISceneSession.Role.windowExternalDisplay in the callback.

Anyone else experienced a similar issue before?

bkokot
  • 71
  • 6
  • In my app this seems to happen automatically since I don't implement this delegate function at all. Can you try commenting out the function? – fruitcoder Jan 07 '22 at 13:26
  • hmm I tried it as well but doesn't seem to work =(. Do you mind sharing your Info.plist scene configuration? – bkokot Jan 09 '22 at 09:04
  • Won't fit in a comment and doesn't make sense as an answer. I have `TemplateSceneConfiguration` and `$(PRODUCT_MODULE_NAME).CarPlaySceneDelegate` in the plist as config name and delegate class name, respectively. The app session role is almost the same (I have a `UILaunchStoryboardName`). You said your app appears on the CarPlay simulator, what happens when you tap the icon? Are your delegate functions called then? – fruitcoder Jan 10 '22 at 09:50
  • When I click on the icon it opens the app and than it loads and gives me the "Unable to connect" error screen.Hmm weird not sure what it could be, I tried with that config also but it didn't work. – bkokot Jan 11 '22 at 17:43
  • Could you download CarPlay sample code from Apple and check that it's not a problem with Xcode/the simulator? – fruitcoder Jan 11 '22 at 18:53

1 Answers1

0

Based on apple's sample code (Integrating CarPlay with Your Music App), you should not initiate CarPlay's scene from AppDelegate, but from the class

CPTemplateApplicationSceneDelegate

This the code part from the sample where CarPlay is connected to your scene.

func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
    MemoryLogger.shared.appendEvent("Template application scene did connect.")
    templateManager.connect(interfaceController)
}