Kaynağa Gözat

Share: keeps original filename

Marino Faggiana 7 yıl önce
ebeveyn
işleme
20a2ee0160
1 değiştirilmiş dosya ile 11 ekleme ve 2 silme
  1. 11 2
      Share/CCloadItemData.swift

+ 11 - 2
Share/CCloadItemData.swift

@@ -87,10 +87,19 @@ class CCloadItemData: NSObject {
                                         
                                         print("item as url: \(String(describing: item))")
                                         
-                                        let pathExtention = URL(fileURLWithPath: url.lastPathComponent).pathExtension
-                                        let fileName = "\(dateFormatter.string(from: Date()))\(conuter).\(pathExtention)"
+                                        let fileName = url.lastPathComponent
+                                        // OLD fileName with date
+                                        //let pathExtention = URL(fileURLWithPath: url.lastPathComponent).pathExtension
+                                        //let fileName = "\(dateFormatter.string(from: Date()))\(conuter).\(pathExtention)"
                                         let filenamePath = directoryUser + "/" + fileName
                                         
+                                        do {
+                                            try FileManager.default.removeItem(atPath: filenamePath)
+                                        }
+                                        catch let error as NSError {
+                                            print("Ooops! Something went wrong: \(error)")
+                                        }
+                                        
                                         do {
                                             try FileManager.default.copyItem(atPath: url.path, toPath:filenamePath)