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]];
网友评论