iosswiftwkwebviewiphone-privateapiapplication-cache

Enabling Application Cache in WkWebView using private API in Swift not working


According to sources (1,2)

The below category that uses private API usually found in Safari lets WkWebView enable Application cache

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

I wanted to implement application cache using Swift so I made the conversion of above code

extension WKPreferences {
    func _setOfflineApplicationCacheIsEnabled(offlineApplicationCacheIsEnabled: Bool) {
    }
}

But in swift its not working.

Here is the sample url that has application cache.I tried this in safari it works perfectly but not in WkWebView


Solution

  • you should import the ObjC version you have above into your bridging file. then in swift call the now exposed method directly.