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.

impresyjna
  • 61
  • 1
  • 2

1 Answers1

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...

daren
  • 51
  • 5