情况一 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 ];
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” ];
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/" ]];
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:///文件所在的文件夹名称/"]
如果加载不出来 断点打印路径,,使用前往文件夹的方法看能不能成功进入,,调整路径拼接直到可以前往便能成功加载