Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView reload() can't refresh current page

the first time load web page fail at offline. then I connect network call reload() to refresh current page, but it is not work, the WKNavigationDelegate can't get any callback.

the function reloadFromOrigin() also not work

but the doc says:

/*! @abstract Reloads the current page.
 @result A new navigation representing the reload.
 */
- (nullable WKNavigation *)reload;

/*! @abstract Reloads the current page, performing end-to-end revalidation
 using cache-validating conditionals if possible.
 @result A new navigation representing the reload.
 */
- (nullable WKNavigation *)reloadFromOrigin;

Can someone help 🍭

like image 235
aboojan Avatar asked Aug 16 '17 06:08

aboojan


People also ask

How do I refresh WKWebView?

The WKWebView already contains a scrollview. All you need to do is create the refresh control, assign a target function that will get called when a user initiates a refresh, and attach the refresh control to the scrollview.

How do I add WKWebView to Objective C?

You can implement WKWebView in Objective-C, here is simple example to initiate a WKWebView : WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; WKWebView *webView = [[WKWebView alloc] initWithFrame:self. view. frame configuration:theConfiguration]; webView.


1 Answers

The first time load web page fail at offline. Then webview.url be nil. Try the following code:

func reloadButtonDidTap() {
    if webview.url != nil {
        webview.reload()
    } else {
        webview.load(URLRequest(url: originalURL))
    }
}
like image 160
Kosuke Ogawa Avatar answered Oct 05 '22 15:10

Kosuke Ogawa