美文网首页
WKWebView加载本地HTML资源的正确姿势

WKWebView加载本地HTML资源的正确姿势

作者: loghdst | 来源:发表于2019-01-24 12:07 被阅读0次

1.首先将资源文件放在同一文件夹(html,css,js等)

2.将资源文件夹添加到工程目录时注意选择Create folder references(即蓝色文件夹)

相关代码:

WKWebViewConfiguration *config = [WKWebViewConfiguration new];

[config.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"];

 self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"fileName"];

[self.webView loadFileURL:[NSURL fileURLWithPath:filePath] allowingReadAccessToURL:[NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]];

相关文章

网友评论

      本文标题:WKWebView加载本地HTML资源的正确姿势

      本文链接:https://www.haomeiwen.com/subject/awsyjqtx.html