WKWeb?View
WKWeb?View
可以參考 http://nshipster.cn/wkwebkit/
UIWeb?View
UIWeb?View
緩存
1.這是官方原版的烁设,根據(jù)測試有網(wǎng)絡(luò)直接讀網(wǎng)絡(luò),沒網(wǎng)絡(luò)才會讀本地
https://github.com/rnapier/RNCachingURLProtocol
2.下面這個是根據(jù)我們的需求來修改了一下,我們的需求是有緩存的話解滓,不用再次聯(lián)網(wǎng)更新的乡翅,節(jié)約玩家的流量兴溜,
因為游戲基本是不會修改的约啊,換了連接以后耗帕,緩存才會更新校仑,這樣就可以實現(xiàn)離線也可以很愉快的玩耍忠售,下次再打開,就秒開啦
https://github.com/BaiCanLin/RNCachingURLProtocol
UIWeb?View
的一些注意點
1.當(dāng)時我們還需要兼容iOS6
版本的系統(tǒng)迄沫,在iOS6
上面稻扬,比如分別有A
和B
兩個控制器,
分別加載2個UIWeb?View
,只有一個會正常運行邢滑,相同的測試在iOS7
以上的版本不會有問題腐螟。
2.如果打著斷點,給WebView
調(diào)試的時候突然間奔潰了困后,把斷點去掉即可乐纸,當(dāng)初被這個給坑死了,谷歌后才知道
UIWeb?View
利用CocoaHTTPServer
開啟本地服務(wù)器摇予,加載本地資源
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
UIWeb?View
實現(xiàn)自動登陸
參考 :
http://www.reibang.com/p/072bbc1e4c33?utm_campaign=hugo&utm_medium=reader_share&utm_content=note
讓UIWeb?View
有類似于微信的加載進度條
https://github.com/ninjinkun/NJKWebViewProgress
UIWeb?View
Javascript
進行交互
1.objective-c
調(diào)用 javascript
:
[webView stringByEvaluatingJavaScriptFromString:@"alert('done')"];
2.可以自定義協(xié)議侧戴,比如一個網(wǎng)頁宁昭,你想調(diào)起原生的應(yīng)用,可以自定義一個協(xié)議酗宋,通過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(@"監(jiān)聽到 webView 分享");
}else if ([[components lastObject] isEqualToString:@"gameover"]) {
DebugLog(@"監(jiān)聽到 webView 游戲結(jié)束");
}
};
3.WebViewJavascriptBridge
是一個Objective-C
與JavaScript
進行消息互通的三方庫
https://github.com/marcuswestin/WebViewJavascriptBridge
試試這個庫很不錯,根據(jù)版本號切換iOS7
<-> iOS8
pod 'KINWebBrowser'