Эх сурвалжийг харах

fix: Open links from text in Safari

Signed-off-by: Julius Härtl <jus@bitgrid.net>
Julius Härtl 2 жил өмнө
parent
commit
7365fca9f3

+ 12 - 1
iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift

@@ -24,7 +24,7 @@
 import UIKit
 import WebKit
 
-class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
+class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMessageHandler, WKUIDelegate {
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     var webView = WKWebView()
@@ -60,6 +60,7 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
         }
         webView = WKWebView(frame: CGRect.zero, configuration: config)
         webView.navigationDelegate = self
+        webView.uiDelegate = self
         view.addSubview(webView)
 
         webView.translatesAutoresizingMaskIntoConstraints = false
@@ -193,6 +194,16 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
     public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
         NCActivityIndicator.shared.stop()
     }
+
+    public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
+        if navigationAction.targetFrame == nil {
+            if let url = navigationAction.request.url, UIApplication.shared.canOpenURL(url) {
+               UIApplication.shared.open(url)
+            }
+        }
+        return nil
+    }
+
 }
 
 extension NCViewerNextcloudText: UINavigationControllerDelegate {