UIWebView和WKWebView一些琐事

WebViewJavascriptBridge

1.load加载 ,去本地查找html路径方式

NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];//这种方式不会去工程中蓝色folder中查找html
NSString *strRoot = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"deploy"];
//strRoot=/Users/liuwei/Library/Developer/CoreSimulator/Devices/3AD005A6-3D89-415E-84E6-797021F9A35E/data/Containers/Bundle/Application/C4379CFE-A113-480C-AF45-BDF7F8645EC3/WKWebView加载本地html.app/deploy
 

2.[NSURL fileURLWithPath:htmlPath] 和 [NSURL URLWithString:htmlPath]的区别

NSLog(@"htmlPath--%@",htmlPath);
NSLog(@"fileURLWithPath--%@,URLWithString--%@",[NSURL fileURLWithPath:htmlPath],[NSURL URLWithString:htmlPath]);
//htmlPath--/var/containers/Bundle/Application/0F25B57D-11D1-414D-B8CF-9CF7B66B0D59/WKWebView加载本地html.app/deploy/index.html
//fileURLWithPath--file:///var/containers/Bundle/Application/0F25B57D-11D1-414D-B8CF-9CF7B66B0D59/WKWebView%E5%8A%A0%E8%BD%BD%E6%9C%AC%E5%9C%B0html.app/deploy/index.html,URLWithString--(null)

3.有人说WKWebView加载本地html,9.0以前不能用loadRequest直接load, 需要先拷贝到沙盒文件夹里去。 http://www.jianshu.com/p/ccb421c85b2e

但是我发现仍然可以加载。不管NSURL用的是fileURLWithPath还是URLWithString, 用 [webView loadRequest:[NSURLRequest requestWithURL:fileURL]];

都能加载出来。

4.断网情况下,UIWebView是加载不了内容的, 除非加入一些3方插件,处理缓存。如JWCacheURLProtocol
我们项目 ,h5做了manfest缓存, 断网情况下仍然可以加载部分内容, 不需要用3方插件做任何其他缓存处理。

5.缓存策略那个超时时间设置是没有作用的。

未完...

此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
原文地址:https://www.cnblogs.com/liuw-flexi/p/6898242.html