问题描述
我正在尝试用sample project替换此carplay webview的汽车游戏应用程序上的地图。
问题是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:此应用仅供我使用,我不会将其发送到应用商店。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)