Browse Source

compdfkit(rn) - 打开文档的bundle路径判断

yangliuhua 2 months ago
parent
commit
9253e65a6e
3 changed files with 10 additions and 2 deletions
  1. 2 1
      ios/ComPDFKitRN.swift
  2. 2 1
      ios/RCTCPDFView.swift
  3. 6 0
      ios/RCTCPDFViewManager.swift

+ 2 - 1
ios/ComPDFKitRN.swift

@@ -138,8 +138,9 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete, UIDocumentPickerDelegat
             var success = false
             
             let homeDiectory = NSHomeDirectory()
+            let bundlePath = Bundle.main.bundlePath
                 
-            if (documentPath.hasPrefix(homeDiectory)) {
+            if (documentPath.hasPrefix(homeDiectory) || documentPath.hasPrefix(bundlePath)) {
                 let fileManager = FileManager.default
                 let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
                 let fileName = document.lastPathComponent

+ 2 - 1
ios/RCTCPDFView.swift

@@ -43,8 +43,9 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
         var success = false
         
         let homeDiectory = NSHomeDirectory()
+        let bundlePath = Bundle.main.bundlePath
             
-        if (documentPath.hasPrefix(homeDiectory)) {
+        if (documentPath.hasPrefix(homeDiectory) || documentPath.hasPrefix(bundlePath)) {
             let fileManager = FileManager.default
             let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
             let fileName = document.lastPathComponent

+ 6 - 0
ios/RCTCPDFViewManager.swift

@@ -32,6 +32,12 @@ class RCTCPDFReaderView: RCTViewManager, RCTCPDFViewDelegate {
         let rtcCPDFView = cpdfViews[tag]
         rtcCPDFView?.saveDocument(completionHandler: { success in
             completionHandler(success)
+            
+            if (success) {
+                if let onChange = rtcCPDFView?.onChange {
+                    onChange(["saveDocument": "saveDocument"])
+                }
+            }
         })
     }