New delegates for carPlay
Asked Answered
D

1

6

I am devleoping navigation app for CarPlay and in iOS 12 there were two methods from CPApplicationDelegate to detect if CarPlay is on:

func application(_ application: UIApplication, didConnectCarInterfaceController interfaceController: CPInterfaceController, to window: CPWindow)

and

func application(_ application: UIApplication, didDisconnectCarInterfaceController interfaceController: CPInterfaceController, from window: CPWindow)

In iOS 13 these methods are deprecated and Apple gave new delegate: CPTemplateApplicationSceneDelegate

I have tried to connect this new delegate CPTemplateApplicationSceneDelegate to my service that provides all actions for CarPlay but only function I see that can help me is:

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration

So my question is how to detect if CarPlay is connected and how to provide action for CarPlay launched in one window of new iOS 13 CarPlay.

Diocesan answered 17/9, 2019 at 12:8 Comment(0)
M
1

---------------------------EDIT------------------------

In general target's settings check "Supports multiple windows". Then in Info.plist add configuration to your carPlay scene role (CPTemplateApplicationSceneSessionRoleApplication), like this: CarPlay info configuration And voilà! Your delegate will invoke at

func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController, to window: CPWindow)

where you can configure your CarPlay controller.

---------------------------END ------------------------

I will try something like this:

func application(_ application: UIApplication,
                 configurationForConnecting connectingSceneSession: UISceneSession, 
                 options: UIScene.ConnectionOptions) -> UISceneConfiguration {

    if connectingSceneSession.role == UISceneSession.Role.carTemplateApplication {  
      if let carPlayScene = connectingSceneSession.scene as? CPTemplateApplicationScene {
        carPlayScene.delegate = self
      }
    }

and then in your delegate's method you should setup your interface like in iOS12

func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController, to window: CPWindow)

Don't know if it works, because my CarPlay simulator crashes...

Marleah answered 18/11, 2019 at 10:37 Comment(2)
What version of Xcode you have? And Simulator for iOS 12 or 13? Because for versions lower than Xcode 11.1 CarPlay Simulator was broken ;)Diocesan
@Diocesan I am stuck at the same position. did the solution work work?Fernery

© 2022 - 2024 — McMap. All rights reserved.