iOS webView 加载本地html 静态资源的路径问题
2017-07-17 本文已影响144人
键盘仔
iOS中webView加载本地html、js、css、image的路径问题
将html、css、js、image等静态资源文件放到同一个目录www,添加到Xcode中使用as folder references
方式

完成

然后使用如下方式加载页面
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"index"
ofType:@"html"
inDirectory:@"www"];
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest* request = [NSURLRequest requestWithURL:fileURL];
[webView loadRequest:request];