Prechádzať zdrojové kódy

New share extension

marinofaggiana 3 rokov pred
rodič
commit
6baa8816ea

+ 5 - 2
Share/NCShareExtension.swift

@@ -326,8 +326,11 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
     func rename(fileName: String, fileNameNew: String) {
         
         if let row = self.filesName.firstIndex(where: {$0 == fileName}) {
-            filesName[row] = fileNameNew
-            tableView.reloadData()
+            
+            if NCUtilityFileSystem.shared.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + fileNameNew)) {
+                filesName[row] = fileNameNew
+                tableView.reloadData()
+            }
         }
     }
     

+ 18 - 5
iOSClient/Utility/NCUtilityFileSystem.swift

@@ -108,13 +108,26 @@ class NCUtilityFileSystem: NSObject {
         }
     }
     
-    @objc func moveFile(atPath: String, toPath: String) {
+    @objc func moveFile(atPath: String, toPath: String) -> Bool {
 
-        if atPath == toPath { return }
+        if atPath == toPath { return true }
     
-        try? FileManager.default.removeItem(atPath: toPath)
-        try? FileManager.default.copyItem(atPath: atPath, toPath: toPath)
-        try? FileManager.default.removeItem(atPath: atPath)
+        do {
+            try FileManager.default.removeItem(atPath: toPath)
+        }
+        catch {
+            print(error)
+        }
+                
+        do {
+            try FileManager.default.copyItem(atPath: atPath, toPath: toPath)
+            try FileManager.default.removeItem(atPath: atPath)
+            return true
+        }
+        catch {
+            print(error)
+            return false
+        }
     }
     
     @objc func moveFileInBackground(atPath: String, toPath: String) {