6

我正在为 CarPlay 开发导航应用程序,在 iOS 12 中,CPApplicationDelegate 提供了两种方法来检测 CarPlay 是否开启:

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

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

在 iOS 13 中,这些方法已被弃用,Apple 提供了新的委托:CPTemplateApplicationSceneDelegate

我试图将这个新的委托 CPTemplateApplicationSceneDelegate 连接到我的服务,该服务为 CarPlay 提供所有操作,但我看到的唯一可以帮助我的功能是:

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

所以我的问题是如何检测 CarPlay 是否已连接以及如何为在新 iOS 13 CarPlay 的一个窗口中启动的 CarPlay 提供操作。

4

1 回答 1

1

- - - - - - - - - - - - - -编辑 - - - - - - - - - - - --

一般目标的设置检查“支持多个窗口”。然后在 Info.plist 中将配置添加到您的 carPlay 场景角色 (CPTemplateApplicationSceneSessionRoleApplication),如下所示: 瞧 CarPlay 信息配置 !您的代表将在

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

您可以在其中配置 CarPlay 控制器。

- - - - - - - - - - - - - -结尾 - - - - - - - - - - - --

我会尝试这样的事情:

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

然后在您的委托方法中,您应该像在 iOS12 中一样设置您的界面

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

不知道有没有用,因为我的 CarPlay 模拟器崩溃了……

于 2019-11-18T10:37:37.527 回答