使用WKWebView显示本地沙盒路径下的图片出现无法显示的情况。
通常我们使用
[self.wkWebView loadHTMLString:html baseURL:baseURL];
这个问题就出现在 baseURL 上,一般我们习惯性的使用nil;
[self.wkWebView loadHTMLString:html baseURL:nil];
这样WKWebView就没有权限访问沙盒了。
baseURL是需要访问的相关文件的目录。这个目录包括HTML文件本身或者用到的资源,比如图片。
其实仔细看看方法的说明就明白了:
/*! @abstract Sets the webpage contents and base URL.
@param string The string to use as the contents of the webpage.
@param baseURL A URL that is used to resolve relative URLs within the document.
@result A new navigation.
*/
- (nullable WKNavigation *)loadHTMLString:(NSString *)string baseURL:(nullable NSURL *)baseURL;
这篇文章还没有评论