Carplay 无法加载 CPTemplate

问题描述

所以我关注了 Apple 的视频,了解如何制作基本的 CarPlay 应用。但我得到一个空白屏幕。而不是列表视图。

我想知道是否有人可以帮助我如何使用 CPTemplate 方法制作简单的列表视图。

import Foundation
import CarPlay

class CarPlaySceneDelegate: UIResponder,CPTemplateApplicationSceneDelegate {
    var interfactController: CPInterfaceController?
 
  func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,didConnect interfaceController: CPInterfaceController) {
    let item = CPListItem(text: "hello",detailText: "This works")
    let jazz = CPListItem(text: "Jazz",detailText: "How about some smooth jazz.")
  
    let listTemplate = CPListTemplate(title: "TEST",sections: [CPListSection(items:[item,jazz])])
    print("HUGE TEST TO SEE IF THIS IS RUNNING")
    self.interfactController?.setRoottemplate(listTemplate,animated: false)
 
  }
}

我知道它会运行,因为我在控制台日志中进行了大量测试以查看它是否正在运行。

只是下一行没有运行/加载。

解决方法

您的 interfaceController 为零。您可以使用委托方法中的 interfaceController 对其进行初始化。

func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,didConnect interfaceController: CPInterfaceController) {
self.interfactController = interfaceController
//your code to load template
}
,

检查info.plist上的规则是否已经更新,是否创建了一个特殊的carplay委托场景