0

我正在尝试用 carplay webview 替换此示例项目的 carplay 应用程序上地图


这里返回根模板的函数,将在CarPlay上显示:

问题是,setRootTemplate 函数需要一个 CPTemplate,而我不知道如何创建模板并在其上放置一个 uiview?

func application(_ application: UIApplication, didConnectCarInterfaceController interfaceController: CPInterfaceController, to window: CPWindow) {
   
        let webViewClass : AnyObject.Type = NSClassFromString("UIWebView")!
        let webViewObject : NSObject.Type = webViewClass as! NSObject.Type
        let webview: AnyObject = webViewObject.init()
        let url = NSURL(string: "https://www.google.com")
        let request = NSURLRequest(url: url! as URL)
        webview.loadRequest(request as URLRequest)
        let uiview = webview as! UIView

        // tried that too...  let myCPTemplateHere = webview as! CPTemplate

        // Here
       
        interfaceController.setRootTemplate(myCPTemplateHere, animated: true)
}

我也试过 WKWebView

let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
let myURL = URL(string:"https://www.apple.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)

非常感谢 !

PS:这个应用是我自己使用的,我不会发送到应用商店。

4

0 回答 0