marinofaggiana 5 年之前
父节点
当前提交
903284b6fe
共有 1 个文件被更改,包括 26 次插入3 次删除
  1. 26 3
      iOSClient/Viewer/NCViewerRichdocument.swift

+ 26 - 3
iOSClient/Viewer/NCViewerRichdocument.swift

@@ -117,6 +117,9 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
             if let param = message.body as? Dictionary<AnyHashable,Any> {
             if let param = message.body as? Dictionary<AnyHashable,Any> {
                 if param["MessageName"] as? String == "downloadAs" {
                 if param["MessageName"] as? String == "downloadAs" {
                     if let values = param["Values"] as? Dictionary<AnyHashable,Any> {
                     if let values = param["Values"] as? Dictionary<AnyHashable,Any> {
+                        guard let type = values["Type"] as? String else {
+                            return
+                        }
                         guard let urlString = values["URL"] as? String else {
                         guard let urlString = values["URL"] as? String else {
                             return
                             return
                         }
                         }
@@ -126,14 +129,34 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
                         guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
                         guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
                             return
                             return
                         }
                         }
+                        
                         let filename = (components.path as NSString).lastPathComponent
                         let filename = (components.path as NSString).lastPathComponent
                         let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + filename
                         let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + filename
                     
                     
+                        if type == "print" {
+                            NCUtility.sharedInstance.startActivityIndicator(view: self, bottom: 0)
+                        }
+                        
                         _ = OCNetworking.sharedManager()?.download(withAccount: metadata.account, url: urlString, fileNameLocalPath: fileNameLocalPath, encode:false, completion: { (account, message, errorCode) in
                         _ = OCNetworking.sharedManager()?.download(withAccount: metadata.account, url: urlString, fileNameLocalPath: fileNameLocalPath, encode:false, completion: { (account, message, errorCode) in
+
                             if errorCode == 0 && account == self.metadata.account {
                             if errorCode == 0 && account == self.metadata.account {
-                                self.documentInteractionController = UIDocumentInteractionController()
-                                self.documentInteractionController.url = URL(fileURLWithPath: fileNameLocalPath)
-                                self.documentInteractionController.presentOptionsMenu(from: self.appDelegate.window.rootViewController!.view.bounds, in: self.appDelegate.window.rootViewController!.view, animated: true)
+                                if type == "print" {
+                                    NCUtility.sharedInstance.stopActivityIndicator()
+                                    let pic = UIPrintInteractionController.shared
+                                    let printInfo = UIPrintInfo.printInfo()
+                                    printInfo.outputType = UIPrintInfo.OutputType.general
+                                    printInfo.orientation = UIPrintInfo.Orientation.portrait
+                                    printInfo.jobName = "Document"
+                                    pic.printInfo = printInfo
+                                    pic.printingItem = URL(fileURLWithPath: fileNameLocalPath)
+                                    pic.present(from: CGRect.zero, in: self, animated: true, completionHandler: { (pci, completed, error) in
+                                        // end.
+                                    })
+                                } else {
+                                    self.documentInteractionController = UIDocumentInteractionController()
+                                    self.documentInteractionController.url = URL(fileURLWithPath: fileNameLocalPath)
+                                    self.documentInteractionController.presentOptionsMenu(from: self.appDelegate.window.rootViewController!.view.bounds, in: self.appDelegate.window.rootViewController!.view, animated: true)
+                                }
                             } else {
                             } else {
                                 self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
                                 self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
                             }
                             }