aboojan
aboojan

Reputation: 143

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 🍭

Upvotes: 9

Views: 19403

Answers (1)

Kosuke Ogawa
Kosuke Ogawa

Reputation: 7451

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))
    }
}

Upvotes: 26

Related Questions