WKWeb?View
WKWeb?View 可以參考 http://nshipster.cn/wkwebkit/
UIWeb?View
UIWeb?View 緩存
1.這是官方原版的,根據(jù)測(cè)試有網(wǎng)絡(luò)直接讀網(wǎng)絡(luò),沒網(wǎng)絡(luò)才會(huì)讀本地
https://github.com/rnapier/RNCachingURLProtocol
2.下面這個(gè)是根據(jù)我們的需求來修改了一下,我們的需求是有緩存的話,不用再次聯(lián)網(wǎng)更新的,節(jié)約玩家的流量,
因?yàn)橛螒蚧臼遣粫?huì)修改的,換了連接以后,緩存才會(huì)更新,這樣就可以實(shí)現(xiàn)離線也可以很愉快的玩耍,下次再打開,就秒開啦
https://github.com/BaiCanLin/RNCachingURLProtocol
UIWeb?View 的一些注意點(diǎn)
1.當(dāng)時(shí)我們還需要兼容iOS6版本的系統(tǒng),在iOS6上面,比如分別有A和B兩個(gè)控制器,
分別加載2個(gè)UIWeb?View,只有一個(gè)會(huì)正常運(yùn)行,相同的測(cè)試在iOS7以上的版本不會(huì)有問題。
2.如果打著斷點(diǎn),給WebView調(diào)試的時(shí)候突然間奔潰了,把斷點(diǎn)去掉即可,當(dāng)初被這個(gè)給坑死了,谷歌后才知道
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.使用非常簡(jiǎn)單,照著官方的Demo試一下就行,建議使用cocopods安裝
https://github.com/robbiehanson/CocoaHTTPServer
UIWeb?View實(shí)現(xiàn)自動(dòng)登陸
參考 :
http://www.itdecent.cn/p/072bbc1e4c33?utm_campaign=hugo&utm_medium=reader_share&utm_content=note
讓UIWeb?View 有類似于微信的加載進(jìn)度條
https://github.com/ninjinkun/NJKWebViewProgress
UIWeb?View Javascript進(jìn)行交互
1.objective-c調(diào)用 javascript :
[webView stringByEvaluatingJavaScriptFromString:@"alert('done')"];
2.可以自定義協(xié)議,比如一個(gè)網(wǎng)頁,你想調(diào)起原生的應(yīng)用,可以自定義一個(gè)協(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是一個(gè)Objective-C與JavaScript進(jìn)行消息互通的三方庫
https://github.com/marcuswestin/WebViewJavascriptBridge
試試這個(gè)庫很不錯(cuò),根據(jù)版本號(hào)切換iOS7 <-> iOS8
pod 'KINWebBrowser'