我知道iOS WKWebView不支持离线应用程序缓存。
这在Safari中已启用,因此我在webkit项目中搜索了负责的代码&发现了这个
WKPreferences
- (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled;
有谁熟悉这种方法?是否可以通过访问此私有方法在iOS中启用应用程序缓存? (我不打算将应用程序发送到Appstore)
答案 0 :(得分:8)
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
答案 1 :(得分:2)
根据Apple的这条推文,从iOS 10开始,WKWebView
现在支持App Cache:
https://twitter.com/andersca/status/743259582252879872
...就像这个WebKit错误报告一样:
https://bugs.webkit.org/show_bug.cgi?id=152490
我已使用此网站在WKWebView
中对此进行了测试:
http://webdbg.com/test/appcache/
并且可以确认它在iOS模拟器和运行iOS 10的设备上都按预期工作。