iOS webView 加载本地html 静态资源的路径问题

2017-07-17  本文已影响144人  键盘仔

iOS中webView加载本地html、js、css、image的路径问题

将html、css、js、image等静态资源文件放到同一个目录www,添加到Xcode中使用as folder references方式

WX20170717-075203@2x.png

完成

278104-b68c2c01e4841544.jpeg

然后使用如下方式加载页面

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"index"
                                                         ofType:@"html"
                                                    inDirectory:@"www"];
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest* request = [NSURLRequest requestWithURL:fileURL];
[webView loadRequest:request];
上一篇 下一篇

猜你喜欢

热点阅读