提问人:jat 提问时间:9/14/2023 最后编辑:jat 更新时间:9/14/2023 访问量:34
templateApplicationScene 中的 iOS CarPlay swift 异步请求
iOS CarPlay swift asynchronous request in templateApplicationScene
问:
我正在尝试使用异步调用中的数据加载一些 CPListItem。使用虚拟数据,这工作正常(不异步调用)
我的 fetchAllFavourites 方法运行正常,但 carPlay 模拟器上未显示任何内容。
import Foundation
import CarPlay
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
var interfaceController: CPInterfaceController?
var stationItems: [CPListItem] = []
func loadList(withStations stations: [CPListItem]) {
let section = CPListSection(items: stations)
let listTemplate = CPListTemplate(title: "Select a station",
sections: [section])
// Set the root template of the CarPlay interface
// to the list template with a completion handler
interfaceController?.setRootTemplate(listTemplate,
animated: true) { success, error in
// add anything you want after setting the root template
}
}
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didConnect interfaceController: CPInterfaceController) {
FetchFavourites().fetchAllFavourites { stations in
for station in stations {
let testStation = CPListItem(text: station.type, detailText: station.adresse, image: UIImage(systemName: "BP"))
testStation.accessoryType = .disclosureIndicator
testStation.handler = { testStation, completion in
print("Clicked")
completion()
}
self.stationItems.append(testStation)
}
self.loadList(withStations: self.stationItems)
}
}
}
答: 暂无答案
评论
interfaceController
self.interfaceController