I am aware that offline application cache is not supported in iOS WKWebView.
This is enabled in Safari, so I searched webkit project for the responsible code & found this
WKPreferences
- (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled;
Anyone familiar with this method? is it possible to enable app cache in iOS by accessing this private methods? (I am not going to ship the app to Appstore)
After initializing the WKWebView, enable the appcache by calling the above method in the following object [_wkWebView.configuration.preferences _setOfflineApplicationCacheIsEnabled:YES]; It will create the ApplicationCache.db file in the Cache directory and allow the web app to work offline. Warning : 2.5.
You create a WKWebViewConfiguration object in your code, configure its properties, and pass it to the initializer of your WKWebView object. The web view incorporates your configuration settings only at creation time; you cannot change those settings dynamically later.
No. Web views do cache but, as with all web caching, there’s no guarantee that they will cache a specific resource. I’m not sure why the web view hasn’t cached the resource you care about — I expect it’d make sense if you drilled down into the caching logic — but ultimately the decision as to what gets cache is the web view’s to make.
Your dynamic query string is the most reliable trick to get WKWebView to force a re-download and avoid the cache. You seem stuck between a rock and a hard place here. However, you did mention "webview within the application". Since you do have everything inside one file, have you considered loading your webview directly from an HTML string?
Yes, we can enable App cache by accessing private API
Create a category for WKPreferences
and add to following method signature.
@interface WKPreferences (MyPreferences)
- (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled;
@end
(I tried performSelector:withObject: but it didn't work. No idea why)
After initializing the WKWebView, enable the appcache by calling the above method in the following object
[_wkWebView.configuration.preferences _setOfflineApplicationCacheIsEnabled:YES];
It will create the ApplicationCache.db file in the Cache directory and allow the web app to work offline.
Warning :
2.5. Apps that use non-public APIs will be rejected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With