I'm having troubles with the following code. It's supposed to load a local HTML file into a WKWebView.
It works fine on any simulator I've tried (ios 12 / ios 13).
For a reason I do not understand yet, it does not work on device. Instead, I get a blank screen. Debugging the webview with the Safari debugger shows that the page is "about:blank". It did not load my file... Why ?
Note that I have checked the existence of the file by downloading the app container from the phone and the file is there...
- (void)loadIndexConteneurWithHash:(NSString *)hash
{
NSString *fileName = @"index.html";
NSString *subpath = hash ? [NSString stringWithFormat:@"%@#%@", fileName, hash] : fileName;
NSString *rootContainerDirectoryPath = [NSFileUtility pathRelativeToContentDirectoryForSubpath:@"/www/v2"];
NSURL *URL = [NSURL URLWithString:subpath relativeToURL:[NSURL fileURLWithPath:rootContainerDirectoryPath]];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0f];
[self.webView performSelectorOnMainThread:@selector(loadRequest:) withObject:request waitUntilDone:true];
}
Edit: this question is NOT a duplicate of Load local web files & resources in WKWebView
I do not load my HTML file from the bundle but from the app container as noted originally in my question. I've also tried the loadFileURL
method and it does not work either.