FileManager says the file does not exist when it does

I have a precedent that requires saving UIImagein a document directory - then UIImageyou need to convert to PDF and save it in the document directory.

PDF TRANSFER CODE

var filePath = NSString(string: self.selectedMedia!.imagePath!)

if FileManager().fileExists(atPath: filePath as String) {

       filePath = filePath.deletingPathExtension as NSString
       filePath = NSString(string: filePath.appendingPathExtension("PDF")!)

       if let image = UIImage(data: self.selectedMedia?.image! as! Data) {

           let rect:CGRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)

           UIGraphicsBeginPDFContextToFile(filePath as String, rect, nil);
           UIGraphicsBeginPDFPageWithInfo(rect, nil);
           UIGraphicsGetCurrentContext();
           image.draw(in: rect)
           UIGraphicsEndPDFContext();

           self.selectedMedia?.imagePath = filePath as String

           CoreData.save()
       }

       self.showPDFEditor()
   }
else {
   print("Missing File At Path \(filePath)")
} 

Release

FileManagersays the file does not exist when it does. The first time this is done, before we create the PDF, FileManager can detect that the PDF image does exist. But After we create the PDF file from the image - although the PNG image is still intact in the document catalog (see Image below for the application container for proof), FileManagersays PNG does not exist?

enter image description here

Question

FileManager ?

+4
1

PDF Documents iOS. iOS root path , . imagePath, , , . , selectedMedia.

- file:///var/mobile/Containers/Data/Application/7A31EDFD-8644-45A5-8381-FE189E27D6E5/Documents/

, - file:///var/mobile/Containers/Data/Application/URID09RE-5711-TI70-1252-OP4G5JH3WDST/Documents/

, Application/someLongNumber/. , , , .


?

, , . , , Media, , , imagePath, Media/theFileName.PNG.

, /Documents . . , . SO answer, , .

, , , :

file:///var/mobile/Containers/Data/Application/URID09RE-5711-TI70-1252-OP4G5JH3WDST/Documents/Media/theFileName.PNG

+11

Source: https://habr.com/ru/post/1658243/


All Articles