0

因此,我关注了 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)
 
  }
}

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

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

4

2 回答 2

0

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

func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
self.interfactController = interfaceController
//your code to load template
}
于 2021-05-05T06:46:03.957 回答
-1

检查 info.plist 上的规则是否已经更新,并且您已经创建了一个特殊的 carplay 代理场景

于 2021-05-20T10:55:14.707 回答