Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

ios - Enable Application cache in WKWebView

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...