I'm trying to replace the map on the carplay app of this sample project by a carplay webview.
Here the function that returns the root template, to be show on CarPlay :
The problem, is that the setRootTemplate function needs a CPTemplate, and I don't know how to create a template and put a uiview on that ?
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)
}
I tried with WKWebView too
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)
Thanks a lot !
PS: This app is for my own usage, I will not send it to the app store.