I have an app where I save a file in a method called send image and there is a save and if I verify the existence of the file it returns true and everything is fine, but then according to some criteria another method must be fired in this method should look for that file that was previously saved and should be sent to a Web service but when I verify the existence of this returns false that no longer exists, is it because this last method is in another controller? Why do not I have an idea? This is the code to save the file: let documentsPath = NSSearchPathForDirectoriesInDomains (.DocumentDirectory, .UserDomainMask, true) [0]
// Imagen y imagen en formato NSData
if let imageData = UIImageJPEGRepresentation(self.imgLugar.image!, 1.0) {
// Creamos la URL final
let filePath = NSURL(fileURLWithPath: documentsPath).URLByAppendingPathComponent(nombreImg)
do {
// Guardamos imagen
print("\(documentsPath)/\(nombreImg)")
try print("guardo: \(imageData.writeToURL(filePath, options: []))")
let fileManager = NSFileManager.defaultManager()
let imgString = fileManager.fileExistsAtPath("\(documentsPath)/\(nombreImg)")
print("existe: \(imgString))")
let rut = "/var/mobile/Containers/Data/Application/80420879-6E5A-4211-8014-EAFAA9273897/Documents/img_49_24"
print("existeAnt: \(fileManager.fileExistsAtPath(rut))")
} catch {
print(error)
}
}
and this is the code in another controller where I look for the image that was previously saved in the appdelegate:
let fileManager = NSFileManager.defaultManager ()
let imgString = fileManager.fileExistsAtPath(String(usuarioLugar.uslImagen))
print(imgString)
the path is the following is the same in both methods: / var / mobile / Containers / Data / Application / 80420879-6E5A-4211-8014-EAFAA9273897 / Documents / img_49_24 the fileExistsAtPath in the first method returns true and in the second false. What can I do or what is this?