Place name on image

1

Good afternoon in my app I take a photo with the camera and then I keep it in the camera's photo album, but it saves it with a name by default I would like to know how to put the name I want to the photo, The code that I have when I save the image is the following:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

        self.guardaImagen = info[UIImagePickerControllerOriginalImage] as? UIImage

        UIImageWriteToSavedPhotosAlbum(self.guardaImagen!, nil, nil, nil);

        self.imagePick.dismissViewControllerAnimated(true, completion: {
            self.performSegueWithIdentifier("envioFotoLink", sender: self)
        })

    }
    
asked by Juan David Gil 08.06.2016 в 00:23
source

1 answer

0

It is not possible using the UIImageWriteToSavedPhotosAlbum method since the image is saved on the reel. It is the system's way of avoiding duplicates in the file name, maintaining a correct synchronization, etc.

For more info UIImageWriteToSavedPhotosAlbum Reference

UPDATE 1

I add code to save image in the folder Documents

// Carpeta Documents
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]

// Nombre imagen
let imageName = "imagen.png"

// Imagen y imagen en formato NSData
if let image = UIImage(named: "image"), let imageData = UIImageJPEGRepresentation(image, 1.0) {

    // Creamos la URL final
    let filePath = NSURL(fileURLWithPath: documentsPath).URLByAppendingPathComponent(imageName)

    do {

        // Guardamos imagen
        try imageData.writeToURL(filePath, options: [])

    } catch {

        print(error)

    }

}
    
answered by 08.06.2016 в 00:39