iOS WebView

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上面,比如分別有AB兩個(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-CJavaScript進(jìn)行消息互通的三方庫

https://github.com/marcuswestin/WebViewJavascriptBridge

試試這個(gè)庫很不錯(cuò),根據(jù)版本號(hào)切換iOS7 <-> iOS8

pod 'KINWebBrowser'
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容