简体   繁体   English

无法在Swift 3中使用没有baseUrl的WKWebView中加载数据?

[英]Can't load Data in a WKWebView with a nil baseUrl in Swift 3?

I'm trying to load some Data in a WKWebView and the compiler won't let me pass in nil nor URL() for the baseUrl parameter. 我正在尝试在WKWebView中加载一些数据,并且编译器不允许我为baseUrl参数传递nilURL() Is there a workaround? 有解决方法吗? I don't care at all about a baseUrl. 我根本不在乎baseUrl。

Below is my code with trying nil and then trying URL() along with the errors, respectively. 下面是我的代码,分别尝试nilURL()以及错误。

self.webView.load(data!, mimeType: "image/png", characterEncodingName: "UTF-8", baseURL: nil);

error: nil is not compatible with expected argument type 'URL'

self.webView.load(data!, mimeType: "image/png", characterEncodingName: "UTF-8", baseURL: URL());

error: cannot invoke initializer for type 'URL' with no arguments

I believe you will always need a baseURL. 我相信您将永远需要一个baseURL。

Just invoke it with URL(string: "http://localhost") 只需使用URL(string: "http://localhost")调用

Browsers always load from a URL and WKWebView behaves like a browser so it requires some sort of base URL. 浏览器总是从URL加载,WKWebView的行为类似于浏览器,因此它需要某种基本URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM