Skip to content

Commit

Permalink
Fix going back from external pages in web view controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mathebox committed Oct 5, 2021
1 parent 0b7a964 commit 9425ccc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion iOS/ViewControllers/Courses/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class WebViewController: UIViewController {
}

private var webViewCanGoBack: Bool {
// WKWebView.canGoBack returns false values. So we check for the initial URL instead.
// WKWebView.canGoBack returns incorrect values as we have to set the headers for the request again.
// So we check for the initial URL instead.
return self.webView.url != self.url
}

Expand Down Expand Up @@ -172,6 +173,7 @@ class WebViewController: UIViewController {

@objc private func goBack() {
guard self.webViewCanGoBack else { return }
self.webView.stopLoading()
self.webView.goBack()
self.updateToolbarButtons()
}
Expand Down Expand Up @@ -243,6 +245,10 @@ extension WebViewController: WKNavigationDelegate {
return decisionHandler(.allow)
}

if navigationAction.navigationType == .backForward {
return decisionHandler(.allow)
}

let userIsLoggedIn = UserProfileHelper.shared.isLoggedIn
let headerIsPresent = navigationAction.request.allHTTPHeaderFields?.keys.contains(Routes.Header.authKey) ?? false

Expand Down

0 comments on commit 9425ccc

Please sign in to comment.