0
votes

i'm using UIImagePickerController in order the user have the choice of choosing a picture to upload either from a camera or from the camera roll. however, i want to add the option of letting pictures taken by the camera be automatically added to the camera roll as well and images taken from the camera roll don't be re-added to camera roll. i tried:

UIImageWriteToSavedPhotosAlbum(info[UIImagePickerControllerOriginalImage], nil, nil, nil);

and it's saving fine, but when i choose a picture from the camera roll it add a duplicate. so i want to stop that. is there a way to know whether the image is taken from the camera or camera roll? i tried identifying the media type but in either cases it returns public.image, so it didn't help.

1

1 Answers

2
votes

In your imagePickerController:didFinishPickingMediaWithInfo: delegate method, check the sourceType of the picker parameter:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // Do whatever you need

    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
        // save image to camera roll
    }
}