WKWebView loadFileURL only works once

I need to upload a local file to WKWebView. I am using the new ios9 method

- (nullable WKNavigation *)loadFileURL:(NSURL *)URL allowingReadAccessToURL:(NSURL *)readAccessURL

It works great for the first download (spelling out the navigation delegation correctly), but if I try to download a new and different file, it does nothing.

The currentItem url in the wkwebview instance has changed. But if I forcibly reload the delegate method didFinishNavigation is called with the previous URL set. I also tried moving forward, but the file that was supposed to be uploaded is current, it is not on the backForwardList.

The code I use to run WKWebView and upload a file:

self.wk_webview = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.wk_webview.scrollView.delegate = self;
self.wk_webview.navigationDelegate = self;
[self.view addSubview:self.wk_webview];

NSURL *url = [NSURL fileURLWithPath:local_path];
[self.wk_webview loadFileURL:url allowingReadAccessToURL:[url URLByDeletingLastPathComponent]];

Am I missing something? I could not find anything like it.

Any help is appreciated, thanks.

+4
1

, , WKWebView UIViewCell ( UIWebView).

WKWebView - ( ).

, allowReadAccessToURL loadFileURL: allowReadAccessToURL: , WKWebView, . - , - allowReadAccessToURL. :

NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0];
[self loadFileURL:request.URL allowingReadAccessToURL:documentsURL];

, .

+5

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


All Articles