0

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.

  • You cannot use a webview (or any view for that matter) in CarPlay. Apple is extremely restrictive with which UI is possible in a car and allowing arbitrary web content would open doors to showing games, videos and all kinds of other distractions from traffic – fruitcoder Jan 11 '21 at 23:28
  • Igor Magès, Can you solved the problem ? Because of I want to make an app like you – Akif Demirezen Aug 28 '21 at 21:22

0 Answers0