I use a WKWebView in my app and use a native login page. Whenever the web app redirects to the login page I catch it and show the native view controller. This works perfectly fine most of the time. However, I've found that every once in a while (in production mainly) some users get shown the web app login page. It's very rare and inconsistent. I was able to see this behavior when coming back into the app after it was in the background for a while.
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let url = navigationAction.request.url {
if (url.absoluteString.contains("/login")) {
decisionHandler(.cancel)
// redirects to native login page
...
return
}
}
decisionHandler(.allow)
}
Also, I do set the delegate BEFORE calling load on the webview.
Any idea what might be going on and how to prevent this from happening?