0

I am working on an application that saves user's created images to the photo library. I need to attach a user name to each saved image so that I can recall these later. As far as I understand (please correct me if I am wrong), if I am saving to the photo library, I can't change the actual file name, so a way around this is to change modify the metadata and write the user name to the description for instance. However, I am completely stuck on how to accomplish this in Swift and I have searched everywhere for an answer. The code I have to save each UIImage is as follows: I have the save option and the input for a user name presented in an alert view.

        // Create the alert controller
        let alertController = UIAlertController(title: "Finished?", message: "Is this your attempt?", preferredStyle: .Alert)

        // Create the actions
        let okAction = UIAlertAction(title: "Yes, save", style: UIAlertActionStyle.Default) {

            UIAlertAction in
            NSLog("OK Pressed")

            if let image = self.mainImageView.image{
                UIImageWriteToSavedPhotosAlbum(image,self,Selector("image:withPotentialError:contextInfo:"),nil)

            }


        }
        let cancelAction = UIAlertAction(title: "No", style: UIAlertActionStyle.Cancel) {
            UIAlertAction in
            NSLog("Cancel Pressed")
            self.mainImageView.image = nil

        }

        alertController.addTextFieldWithConfigurationHandler { (textField : UITextField!) -> Void in
            textField.placeholder = "Enter User Name"
            self.inputTextField = textField

        }

        // Add the actions
        alertController.addAction(okAction)
        alertController.addAction(cancelAction)

        // Present the controller
        self.presentViewController(alertController, animated: true, completion: nil)

And I have another function for the image, which is as follows:

func image(image: UIImage, withPotentialError error: NSErrorPointer, contextInfo: UnsafePointer<()>) {
    NSLog("\(self.inputTextField.text)")

    let alertController = UIAlertController(title: "Success!", message:"Your image was saved", preferredStyle: .Alert)
   //Some additional code here, specific to another part of the app that has to occur after the image is saved
    self.presentViewController(alertController, animated: true){}

}

This code works to save an image, however I am completely at a loss for how to add anything to the metadata of an image. If anyone has any suggestions or advice it would be greatly appreciated and please let me know if anything is unclear and I can edit or clarify in the comments.

aestrivex
  • 5,170
  • 2
  • 27
  • 44
abovezero
  • 63
  • 2
  • 11
  • 3
    http://stackoverflow.com/questions/9006759/how-to-write-exif-metadata-to-an-image-not-the-camera-roll-just-a-uiimage-or-j – Harshal Bhavsar Mar 11 '16 at 17:45
  • Please let me know if I'm missing something, but I don't think that answer entirely solves my issue. I need to have these images saved to the photo library (camera roll) – abovezero Mar 11 '16 at 21:58

0 Answers0