Explorar el Código

ComPDFKit) - 沙盒结构调整

yangliuhua hace 1 semana
padre
commit
a128ba0b85
Se han modificado 2 ficheros con 32 adiciones y 22 borrados
  1. 16 11
      ios/ComPDFKitRN.swift
  2. 16 11
      ios/RCTCPDFView.swift

+ 16 - 11
ios/ComPDFKitRN.swift

@@ -141,18 +141,23 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete, UIDocumentPickerDelegat
             let bundlePath = Bundle.main.bundlePath
 
             if (documentPath.hasPrefix(homeDiectory) || documentPath.hasPrefix(bundlePath)) {
-                let fileManager = FileManager.default
-                let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
-                let fileName = document.lastPathComponent
-                let docsFilePath = samplesFilePath + "/" + fileName
-
-                if !fileManager.fileExists(atPath: samplesFilePath) {
-                    try? FileManager.default.createDirectory(atPath: samplesFilePath, withIntermediateDirectories: true, attributes: nil)
+                let documentHome = homeDiectory.appending("/Documents")
+                if documentPath.hasPrefix(homeDiectory) && documentPath.hasPrefix(documentHome) {
+                    
+                } else {
+                    let fileManager = FileManager.default
+                    let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
+                    let fileName = document.lastPathComponent
+                    let docsFilePath = samplesFilePath + "/" + fileName
+                    
+                    if !fileManager.fileExists(atPath: samplesFilePath) {
+                        try? FileManager.default.createDirectory(atPath: samplesFilePath, withIntermediateDirectories: true, attributes: nil)
+                    }
+                    
+                    try? FileManager.default.copyItem(atPath: document.path, toPath: docsFilePath)
+                    
+                    documentPath = docsFilePath
                 }
-
-                try? FileManager.default.copyItem(atPath: document.path, toPath: docsFilePath)
-
-                documentPath = docsFilePath
             } else {
                 success = document.startAccessingSecurityScopedResource()
             }

+ 16 - 11
ios/RCTCPDFView.swift

@@ -46,18 +46,23 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
         let bundlePath = Bundle.main.bundlePath
         
         if (documentPath.hasPrefix(homeDiectory) || documentPath.hasPrefix(bundlePath)) {
-            let fileManager = FileManager.default
-            let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
-            let fileName = document.lastPathComponent
-            let docsFilePath = samplesFilePath + "/" + fileName
-            
-            if !fileManager.fileExists(atPath: samplesFilePath) {
-                try? FileManager.default.createDirectory(atPath: samplesFilePath, withIntermediateDirectories: true, attributes: nil)
+            let documentHome = homeDiectory.appending("/Documents")
+            if documentPath.hasPrefix(homeDiectory) && documentPath.hasPrefix(documentHome) {
+                
+            } else {
+                let fileManager = FileManager.default
+                let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
+                let fileName = document.lastPathComponent
+                let docsFilePath = samplesFilePath + "/" + fileName
+                
+                if !fileManager.fileExists(atPath: samplesFilePath) {
+                    try? FileManager.default.createDirectory(atPath: samplesFilePath, withIntermediateDirectories: true, attributes: nil)
+                }
+                 
+                try? FileManager.default.copyItem(atPath: document.path, toPath: docsFilePath)
+                
+                documentPath = docsFilePath
             }
-            
-            try? FileManager.default.copyItem(atPath: document.path, toPath: docsFilePath)
-            
-            documentPath = docsFilePath
         } else {
             success = document.startAccessingSecurityScopedResource()
         }