Carplay 连接/断开事件?

weu*_*uhi 5 ios carplay swift

有没有办法在应用程序中检测手机是否使用 Carplay 与汽车连接/断开连接?似乎找不到任何关于它的文档。我正在考虑一些我可以监控的系统事件。

Ale*_*pov 1

您遵循这些步骤了吗?

  1. 将相应的记录添加到项目的权利文件中:com.apple.developer.carplay-maps类型为Boolean带值YES
  2. 向Apple请求相应的权限
  3. 让您的 AppDelegate 确认CPApplicationDelegate协议
  4. 实现以下方法:

    /**
     The CarPlay screen has connected and is ready to present content.
    
     Your app should create its view controller and assign it to the @c rootViewController property
     of this window.
    
     @note It is the responsibility of the delegate to maintain a reference to the interface controller beyond the scope of this method.
     */
    - (void)application:(UIApplication *)application didConnectCarInterfaceController:(CPInterfaceController *)interfaceController toWindow:(CPWindow *)window;
     /**
     The CarPlay screen has disconnected.
      */
    - (void)application:(UIApplication *)application didDisconnectCarInterfaceController:(CPInterfaceController *)interfaceController fromWindow:(CPWindow *)window;
    
    Run Code Online (Sandbox Code Playgroud)

请查看此文档链接此 WWDC 2018 Carplay 会议

  • 请注意,这仅适用于 CarPlay 导航应用程序。音频应用程序不需要关心该连接状态。 (2认同)