4

I was trying to use the new WebView in my app, but it seems that WKWebView can't work with NSURLCache, and Manifest request didn't work, no request was loaded and also nothing was stored.

Everything seems to work better using WKWebView instead of UIWebView except for using NSURLCache and Manifest, so I wonder if there are some ways to solve this matter.

P.S. I've tried Private API _setOfflineApplicationCacheIsEnabled: and it does work, but app using non-public API will be rejected by apple... I'm now out of ideas.

Nicknow
  • 7,154
  • 3
  • 22
  • 38
humphry
  • 41
  • 5

1 Answers1

4

Right now, 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.

Tanuj
  • 531
  • 4
  • 10