WKWebView instances will ignore any of the default networking storages (NSURLCache, NSHTTPCookieStorage, NSCredentialStorage) and also the standard networking classes you can use to customize the network requests (NSURLProtocol, etc.).
So the cookies of the WKWebView instance are not stored in the standard Cookie storage of your App, and so NSURLSession/NSURLConnection which only uses the standard Cookie storage has no access to the cookies of WKWebView (and exactly this is probably the problem you have: the ?login status“ is most likely stored in a cookie, but NSURLSession/NSURLConnection won’t see the cookie).
The same is the case for the cache, for the credentials etc. WKWebView has its own private storages and therefore does not play well with the standard Cocoa networking classes.
You also can’t customize the requests (add your own custom HTTP headers, modify existing headers, etc), use your own custom URL schemes etc, because also NSURLProtocol is not supported by WKWebView.
So right now WKWebView is pretty useless for many Apps, because it does not participate with the standard networking APIs of Cocoa.
I still hope that Apple will change this until iOS 8 gets released, because otherwise WKWebView will be useless for many Apps, and we are probably stick with UIWebView a little bit longer.
So send bug reports to Apple, so Apple gets to know that these issues are serious and needs to be fixed
NSURLCache和NSHTTPCookieStroage無法操作(WKWebView)WebCore進(jìn)程的緩存和Cookie偶垮。
WKWebView實(shí)例將會忽略任何的默認(rèn)網(wǎng)絡(luò)存儲器(NSURLCache, NSHTTPCookieStorage, NSCredentialStorage) 和一些標(biāo)準(zhǔn)的自定義網(wǎng)絡(luò)請求類(NSURLProtocol,等等.)。
WKWebView實(shí)例不會把Cookie存入到App標(biāo)準(zhǔn)的的Cookie容器(NSHTTPCookieStorage)中,因?yàn)?NSURLSession/NSURLConnection等網(wǎng)絡(luò)請求使用NSHTTPCookieStorage進(jìn)行訪問Cookie,所以不能訪問WKWebView的Cookie嚎卫,現(xiàn)象就是WKWebView存了Cookie掠抬,其他的網(wǎng)絡(luò)類如NSURLSession/NSURLConnection卻看不到闸与。
與Cookie相同的情況就是WKWebView的緩存,憑據(jù)等涉兽。WKWebView都擁有自己的私有存儲,因此和標(biāo)準(zhǔn)Cocoa網(wǎng)絡(luò)類兼容的不是那么好嗤谚。
你也不能自定義requests(增加自己的http header,更改已經(jīng)存在的header)使用自定義的 URL schemes等等藏畅,因?yàn)镹SURLProtocol也是不支持WKWebView的敷硅。
在用AFN進(jìn)行網(wǎng)絡(luò)請求,NSURLSession會使用NSHTTPCookieStorage進(jìn)行訪問Cookie,但是wkwebview并沒有把cookie存放到NSHTTPCookieStorage中,也就是post/get請求中并不會帶有cookie,導(dǎo)致server端cookie校驗(yàn)失敗,重新生成cookie.看似登錄其實(shí)并未登錄.
那么,手動之.
頁面退出時(shí),由于NSHTTPCookieStorage中仍然存在cookie,需要手動清除
至此cookie,脫坑
stackoverflow.com/questions/24464397/how-can-i-retrieve-a-file-using-WKWebView