I am loading a content from a google drive document (published) in a WKWebView but I cannot get some of the links to open. I am trying to open them in Safari, but if I can get them to open inside the webview is ok also.
I am using the WKUIDelegate with this method:
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
let url = navigationAction.request.url!
print(navigationAction.request.url!)
if navigationAction.targetFrame == nil, UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(navigationAction.request.url!, options: [:], completionHandler: nil)
}
return nil
}
The issue here is that navigationAction.request.url! is "" (empty) for some links and so I cannot open them (canOpenURL returns false)
For example, the links I cannot open look like this:
<a class="c6" href="https://www.google.com/url?q=https://www.youtube.com/watch?v%3DYK.....">Tutorial</a>
And the links I can open:
<a target="_blank" title="Learn more about Google Drive" href="//docs.google.com/">Google Drive</a>
In the last case, the navigationAction.request.url is valid as written in the tag.
Is there a way to solve this?
EDIT: I tried long press on a link and copy link and it seems that the URL is copied correctly, so there is no problem in the loaded html.
After another few tests I discovered that some issues are with the actual links, for example if I try to open https://google.com/url.... https://docs.google.com... or youtube.com or some other sites it works, but if I try to open https://www.google.com/... it does not work