I am trying to shift my app from UIWebView to WKWebView. When the app starts, my App is downloading an HTML file to the file system. When the download is over, a webview object is created (not presented on screen) and loading the HTML from the device (“file://“). The HTML contains javascript that loads resources from URLs according to certain params. Here is the issues:
- In UIWebview, all resources are loaded without a problem.
- In WKWebView there is a weird behavior:
If the object (WKWebView) is not presented on screen - resources not being loaded and the general flow of JavaScript is very slow. If the object (WKWebView) is presented on screen - all resources are loaded, general flow is good behave as UIWebView.
My Question is - Why WKWebView behaves differently when presented on screen? Is it related to the fact that the HTML is being loaded from the file system? As Far as I remember, WKWebView should load everything normally if its instance exist, without any dependency on wether it's presented or not.
This is how i am loading the file:
//convert to file system url
NSURL *fileSystemLocation = [[NSURL alloc] initFileURLWithPath:[getting the path] isDirectory:YES];
//load the html file
[self.wkwebview loadFileRequest:requestToHtml allowingReadAccessToURL:fileSystemLocation];
The Html contains a long script inside the script tag. It's main line are doing something like:
var js = someVar.getElementsByTagName(someName);
js = someVar.createElement(someVar);
js.src = geSomeUrl(); //behave differnatly when webview is not presented