WKWebView Cache not working iOS8

The cache manifest works fine and events fire on safari on iOS 8. Doesn’t work at all on WKWebView, does anyone else solve this problem?

import UIKit

import WebKit

class ViewController: UIViewController { @IBOutlet var containterView : UIView! = nil var webView : WKWebView? override func loadView(){ super.loadView() self.webView = WKWebView() self.view = self.webView! } override func viewDidLoad() { super.viewDidLoad() var url = NSURL(string:"http://html5demos.com/offlineapp") var req = NSURLRequest(URL:url) self.webView!.loadRequest(req) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } 

}

Application cache returned as supported if I have to use html5test.com

EDIT:

window.applicationCache does not return undefined either when loading from WKWebView

 console.log("Initializing Page"); if (window.applicationCache == undefined){ console.log("Application cache not suported!"); updateSplash(); } console.log(window.applicationCache); returns: DOMApplicationCache 

EDIT 2:

 if (typeof window.applicationCache.update === 'function'){ console.log("Application has method update"); console.log(window.applicationCache.update); //shows swapCache() and update() methods window.applicationCache.update(); } 

window.applicationCAche.update () throws Error: InvalidStateError: DOM Exception 11: An attempt was made to use an object that is no longer or can no longer be used.

+6
source share
2 answers

Just for the record, this question seems to have been asked and related to the Apple Developer Forums . Apple's official answer is that HTML5 application cache functionality is not available in WKWebView:

The offline application cache is not included in WKWebView. Feel free to ask for it to be available through https://bugreport.apple.com .

+2
source

I think you are trying to solve the same problem as me. That's what I'm doing.

  • Save the start page of your web application in a single HTML file (index.html), inserting everything (CSS, JS, images as base 64, font icons). And add this file to your Xcode project.
  • Launch the application by reading the contents of the HTML file and loading it into WKWebView. You can set the database as the same URL from which you should start. Thus, it will be shown that the web application opens on your website.

The advantage is that your application will always start, even if the user's network is not suitable. It uses SWIFT-Code, courtesy of Matt Neuberg ( https://books.google.com/books?id=wLaVBQAAQBAJ&pg=PT669&lpg=PT669&dq=addConstraints+wkwebview&source=bl&ots=7trE7MR1zR&sig=VT6GDBGbDw9dh89wDb5Uajd4gUY&hl=en&sa=X&ei=cyyeVNH4MM3ToATukoDgAQ&ved=0CDkQ6AEwBA#v = onepage & q = addConstraints% 20wkwebview & f = false ). If you want to get the full source code, let me know and I will post it on Github.

  let templatepath = NSBundle.mainBundle().pathForResource("index", ofType: "html")! let base = NSURL(string:"http://m.ftchinese.com/iphone-2014.html#iOSShare") var s = NSString(contentsOfFile:templatepath, encoding:NSUTF8StringEncoding, error:nil)! self.webView!.loadHTMLString(s, baseURL:base) 
+1
source

Source: https://habr.com/ru/post/976305/


All Articles