1

I am working on an application which it access to the camera and it can take photos. the problem is that it dose not save the image to the camera roll as soon as it takes it. I searched a lot and it seems I should implement an image view but I do not need the exact image on the screen of my application. Is there any way which I can save image to camera roll as soon as I take it without using of imageView?

Here is my code for imagePickerController

 @IBAction func openCameraButton(_ sender: AnyObject)
{
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)
    }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        imagePicked.contentMode = .scaleToFill
        imagePicked.image = pickedImage
    }
    picker.dismiss(animated: true, completion: nil)
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
neda Derakhshesh
  • 1,103
  • 2
  • 20
  • 43
  • 1
    I Think it's Help full https://stackoverflow.com/questions/36073638/uiimagepickercontroller-didfinishpickingmediawithinfo-not-being-called – user2296278 Feb 03 '18 at 14:56

1 Answers1

3

here is Delegate code you can use this code for Saving ASAP Just Add 2 line codes and you will remove this part ( imagePicked.image = pickedImage ) Because you can't see image before finish close Picker (picker.dismiss)

Don't Forget to Add 2 Line in info.Plist enter image description here

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

    UIImageWriteToSavedPhotosAlbum(pickedImage!, nil, nil, nil);
    picker.dismiss(animated: true, completion: nil)

    imagePicked.contentMode = .scaleToFill
    imagePicked.image = pickedImage



    }

}
user2296278
  • 528
  • 1
  • 4
  • 17