Using custom fonts in WKWebView

I faced same issue, in my case i could fix it WITHOUT using base64 encoding and GCDWebServer. Scenario: WkWebView loading is through string html WkWebView is using local .css Fonts are local and are added at top level project Entries for fonts are provided in appName-info.plist under key UIAppFonts / Fonts provided by application (Note: … Read more

WkWebView does not load links to pdfs

There are a few things you can check: Verify that the <a href links doesn’t contain target=”_blank” attribute since WKWebView doesn’t know how to open the link in a new tab. see https://stackoverflow.com/a/25853806/810466 for how to work around that. Check if the link is HTTPS or update the App Transport Security Settings with the Allow … Read more

How to remove cache in WKWebview?

Updated Swift 5 version: WKWebsiteDataStore.default().removeData(ofTypes: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache], modifiedSince: Date(timeIntervalSince1970: 0), completionHandler:{ }) Swift version: if #available(iOS 9.0, *) { let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache]) let date = NSDate(timeIntervalSince1970: 0) WKWebsiteDataStore.defaultDataStore().removeDataOfTypes(websiteDataTypes as! Set<String>, modifiedSince: date, completionHandler:{ }) } else { var libraryPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, false).first! libraryPath += “/Cookies” do { try NSFileManager.defaultManager().removeItemAtPath(libraryPath) } catch … Read more

WKWebView Persistent Storage of Cookies

This is actually a tough one because there’s a) some bug that’s still not solved by Apple (I think) and b) depends on what cookies you want, I think. I wasn’t able to test this now, but I can give you some pointers: Getting cookies from NSHTTPCookieStorage.sharedHTTPCookieStorage(). This one seems buggy, apparently the cookies aren’t … Read more

How can I retrieve a file using WKWebView?

Right now, WKWebView instances will ignore any of the default networking storages (NSURLCache, NSHTTPCookieStorage, NSCredentialStorage) and also the standard networking classes you can use to customize the network requests (NSURLProtocol, etc.). So the cookies of the WKWebView instance are not stored in the standard Cookie storage of your App, and so NSURLSession/NSURLConnection which only uses … Read more

Enable Application cache in WKWebView

Update 2022 According to one of the comments below, this hack doesn’t work anymore. 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, … Read more