Search code examples
swiftwkwebview

Swift - WKWebView is not opening links from websitesI


I have the next policy in my WKWebView

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
        switch navigationAction.navigationType {
        case .linkActivated:
            decisionHandler(.allow)
            return
        default:
            break
        }
        decisionHandler(.allow)
    }

But, every time I try to open a link, I get:

BackgroundTask] Background Task 7 ("GDTCCTUploader-upload"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this

[Feedback] failed initializing core haptics engine for <_UIFeedbackCoreHapticsEngine: 0x283fc3aa0>: Error Domain=com.apple.CoreHaptics Code=-4810 "(null)"

I don't have anything special on my project, just the browser, but it is not allowing me to open web sites likes.

Why is giving me that error and how can I solve it?

UPDATE

This happens when I search in google the word cuevana and try to open the link,

The other browser can open the site, but that site produces a lot of error, like this:

Feedback] failed initializing core haptics engine for <_UIFeedbackCoreHapticsHapticsOnlyEngine: 0x282e49570>: Error Domain=com.apple.CoreHaptics Code=-4810 "(null)"


Solution

  • For some reason, I have to implement this;

    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
            
            if navigationAction.navigationType == WKNavigationType.linkActivated {
                let url = navigationAction.request.url!.absoluteString
                
                let shared = UIApplication.shared
                webview.load(url)
                decisionHandler(WKNavigationActionPolicy.allow)
                return
                
            }
    
            decisionHandler(WKNavigationActionPolicy.allow)
        }