Browse Source

fix hyperlink

marinofaggiana 4 years ago
parent
commit
eeb00809a7
1 changed files with 10 additions and 9 deletions
  1. 10 9
      iOSClient/Viewer/NCViewerRichdocument.swift

+ 10 - 9
iOSClient/Viewer/NCViewerRichdocument.swift

@@ -122,6 +122,7 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
             }
             
             if let param = message.body as? Dictionary<AnyHashable,Any> {
+                
                 if param["MessageName"] as? String == "downloadAs" {
                     if let values = param["Values"] as? Dictionary<AnyHashable,Any> {
                         guard let type = values["Type"] as? String else {
@@ -181,6 +182,15 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
                         metadata.fileName = newName
                         metadata.fileNameView = newName
                     }
+                } else if param["MessageName"] as? String == "hyperlink" {
+                    if let values = param["Values"] as? Dictionary<AnyHashable,Any> {
+                        guard let urlString = values["Url"] as? String else {
+                            return
+                        }
+                        if let url = URL(string: urlString) {
+                            UIApplication.shared.open(url)
+                        }
+                    }
                 }
             }
             
@@ -191,15 +201,6 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
             if message.body as? String == "paste" {
                 self.paste(self)
             }
-            
-            if (message.body as? String)?.hasPrefix("HYPERLINK") != nil {
-                if let messageBodyItem = (message.body as? String)?.components(separatedBy: " ") {
-                    if messageBodyItem.count >= 2 {
-                        let url = URL(fileURLWithPath: messageBodyItem[1])
-                        UIApplication.shared.open(url, options: [:]) { (_) in }
-                    }
-                }
-            }
         }
     }