WKWebView
WKWebView
可以参考 http://nshipster.cn/wkwebkit/
UIWebView
UIWebView
缓存
1.这是官方原版的,根据测试有网络直接读网络,没网络才会读本地
https://github.com/rnapier/RNCachingURLProtocol
2.下面这个是根据我们的需求来修改了一下,我们的需求是有缓存的话,不用再次联网更新的,节约玩家的流量,
因为游戏基本是不会修改的,换了连接以后,缓存才会更新,这样就可以实现离线也可以很愉快的玩耍,下次再打开,就秒开啦
https://github.com/BaiCanLin/RNCachingURLProtocol
UIWebView
的一些注意点
1.当时我们还需要兼容iOS6
版本的系统,在iOS6
上面,比如分别有A
和B
两个控制器,
分别加载2个UIWebView
,只有一个会正常运行,相同的测试在iOS7
以上的版本不会有问题。
2.如果打着断点,给WebView
调试的时候突然间奔溃了,把断点去掉即可,当初被这个给坑死了,谷歌后才知道
UIWebView
利用CocoaHTTPServer
开启本地服务器,加载本地资源
1.官方介绍
CocoaHTTPServer is a small, lightweight, embeddable HTTP server for Mac OS X or iOS applications.
Sometimes developers need an embedded HTTP server in their app.
Perhaps it's a server application with remote monitoring.
Or perhaps it's a desktop application using HTTP for the communication backend.
Or perhaps it's an iOS app providing over-the-air access to documents.
Whatever your reason, CocoaHTTPServer can get the job done. It provides:
Built in support for bonjour broadcasting
IPv4 and IPv6 support
Asynchronous networking using GCD and standard sockets
Password protection support
SSL/TLS encryption support
Extremely FAST and memory efficient
Extremely scalable (built entirely upon GCD)
Heavily commented code
Very easily extensible
WebDAV is supported too!
2.使用非常简单,照着官方的Demo
试一下就行,建议使用cocopods
安装
https://github.com/robbiehanson/CocoaHTTPServer
UIWebView
实现自动登陆
参考 :
http://www.jianshu.com/p/072bbc1e4c33?utm_campaign=hugo&utm_medium=reader_share&utm_content=note
让UIWebView
有类似于微信的加载进度条
https://github.com/ninjinkun/NJKWebViewProgress
UIWebView
Javascript
进行交互
1.objective-c
调用 javascript
:
[webView stringByEvaluatingJavaScriptFromString:@"alert('done')"];
2.可以自定义协议,比如一个网页,你想调起原生的应用,可以自定义一个协议,通过UIWebView
中的委托 shouldStartLoadWithRequest
方法。
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@"://"];
if ([components count] > 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"这里一般写公司域名"]) {
if ([[components lastObject] isEqualToString:@"share"]){
DebugLog(@"监听到 webView 分享");
}else if ([[components lastObject] isEqualToString:@"gameover"]) {
DebugLog(@"监听到 webView 游戏结束");
}
};
3.WebViewJavascriptBridge
是一个Objective-C
与JavaScript
进行消息互通的三方库
https://github.com/marcuswestin/WebViewJavascriptBridge
试试这个库很不错,根据版本号切换iOS7
<-> iOS8
pod 'KINWebBrowser'