UIWebview和WKWebview加载本地html
2017-12-20 15:49
513 查看
情况一 html文件不在文件夹里
NSURL *url = [[NSBundle
mainBundle] URLForResource:@"test"
withExtension:@"html"];
NSURLRequest *request = [NSURLRequest
requestWithURL:url];
[_webView loadRequest:request];
情况二 html文件在文件夹里
1 添加文件夹时 选择Create folder references
//////// 对于UIWebview的加载方法
@———1
NSString
*documentPath=[[NSBundle
mainBundle]
bundlePath];
NSString
*filePath = [NSString
stringWithFormat:@"%@%@",documentPath,@"/video-js/index.htm"];
NSString
*htmlString = [NSString
stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:nil];
[self.newsWebView
loadHTMLString:htmlString
baseURL:[NSURL
URLWithString:filePath]];
@———2
NSString
*documentPath=[[NSBundle
mainBundle]
bundlePath];
NSString
*filePath = [NSString
stringWithFormat:@"%@%@",documentPath,@"/video-js/index.htm”];
[_webView
loadRequest:[NSURLRequest
requestWithURL:[NSURL
URLWithString:filePath]]];
//// 对于WKWebview的加载方法
NSString
*documentPath=[[NSBundle
mainBundle]
bundlePath];
NSString
*filePath = [NSString
stringWithFormat:@"%@%@",documentPath,@"/video-js/index.htm"];
NSString
*htmlString = [NSString
stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:nil];
[self.newsWebView
loadHTMLString:htmlString
baseURL:[NSURL
URLWithString:@"file:///video-js/"]];
上一行的 baseURL ::: [NSURL URLWithString:@"file:///文件所在的文件夹名称/"]
如果加载不出来 断点打印路径,,使用前往文件夹的方法看能不能成功进入,,调整路径拼接直到可以前往便能成功加载
相关文章推荐
- WKWebView和UIWebView加载本地html和JS交互各种坑解决办法
- IOS开发(7)WKWebView加载本地HTML、CSS、JS文件JS(解决html内访问其他资源路径问题)
- iOS中wkwebview加载本地html的要点
- iOS 加载HTML的相关问题(与JS的互相调用和WKWebView加载本地网页)
- ios webView 加载本地html5
- android WebView 控件加载本地sdcard中html文件图片的问题
- iOS WebView加载本地html文件
- android webview 加载本地html并且解决多图卡顿问题
- WKWebView 使用HTML 播放本地视频
- android stuido WebView 如何本地加载html
- webview html页面加载本地js及img src(一)
- android webView不能加载本地html文件问题
- WebView加载本地Html文件并实现点击效果
- webView如何加载本地html文件
- WebView加载本地html需要处理同源策略
- WKWebView 加载本地JS、htlm文件
- webview html页面加载本地js及img src(二)
- Android的webview加载本地html、本apk内html和远程URL
- IOS 使用 WKWebView 加载本地的JS和CSS文件出现乱码问题
- webview加载本地404 html