在WKWebView中启用应用程序缓存 [英] Enable Application cache in WKWebView

查看:482
本文介绍了在WKWebView中启用应用程序缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道iOS WKWebView不支持离线应用程序缓存。

I am aware that offline application cache is not supported in iOS WKWebView.

这是在Safari中启用的,所以我在webkit项目中搜索了负责任的代码&发现了这个

This is enabled in Safari, so I searched webkit project for the responsible code & found this

WKPreferences

- (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled;

是否有人熟悉此方法?是否可以通过访问此私有方法在iOS中启用应用程序缓存? (我不打算将应用程序发送到Appstore)

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)

推荐答案

是的,我们可以通过访问私有API启用App缓存

Yes, we can enable App cache by accessing private API

WKPreferences 创建一个类别,并添加到以下方法签名。

Create a category for WKPreferences and add to following method signature.

@interface WKPreferences (MyPreferences)
- (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled;
@end

(我试过performSelector:withObject:但它没有不知道为什么)

初始化WKWebView后,通过调用以下对象中的上述方法启用appcache

After initializing the WKWebView, enable the appcache by calling the above method in the following object

  [_wkWebView.configuration.preferences _setOfflineApplicationCacheIsEnabled:YES];

它将在Cache目录中创建ApplicationCache.db文件,并允许Web应用程序脱机工作。

It will create the ApplicationCache.db file in the Cache directory and allow the web app to work offline.

警告:


2.5。使用非公开API的应用将被拒绝

2.5. Apps that use non-public APIs will be rejected

这篇关于在WKWebView中启用应用程序缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆