9

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

aboojan
  • 143
  • 1
  • 1
  • 6
  • 2
    If the first URL WKWebView tries to load fails, the active URL will be nil. On every reload call it will be trying to load nil. You can check the URL parameter of the webview before reloading. – koropok Aug 16 '17 at 07:31

1 Answers1

24

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))
    }
}
Peter Schorn
  • 916
  • 3
  • 10
  • 20
Kosuke Ogawa
  • 7,383
  • 3
  • 31
  • 52
  • 1
    To avoid a Swift warning about unused url variable, fix the "if" line to: if let _ = webview.url { – Smartcat Aug 08 '19 at 17:11