swift CarPlay setRootTemplate已弃用

eyh26e7m  于 2023-05-16  发布在  Swift
关注(0)|答案(1)|浏览(149)

所以我现在用

let listTemplate = CPListTemplate(title: "name", sections: sections)
        interfaceController?.setRootTemplate(listTemplate, animated: true)

设置模板,但Xcode告诉我:'setRootTemplate(_:animated:)' was deprecated in iOS 14.0
有什么新方法可以做到这一点?

nxagd54h

nxagd54h1#

使用The New One With Completion In Docs

interfaceController?.setRootTemplate(listTemplate, animated: true,completion:nil)

也可以使用异步版本

Task {
  do {
      let listTemplate = CPListTemplate(title: "name", sections: sections)
      try await interfaceController.setRootTemplate(listTemplate, animated: true)
  }
  catch {
      print(error)
  }
}

相关问题