Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerViewerController crashes when attempting to go to saved photos (on iPhone)

I have a UIImagePickerViewerController. It works perfectly when I select UIImagePickerControllerSourceTypeCamera. However, when I go try to select UIImagePickerControllerSourceTypeSavedPhotosAlbum, it crashes with this error:

2011-09-14 01:41:21.779 NG911[378:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera'

Here is the code I have:

        if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] || ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                message:@"This device does not support a photo library"
                                                               delegate:nil
                                                      cancelButtonTitle:@"OK"
                                                      otherButtonTitles:nil, nil];
        [noCameraAlert setTag:2];
        [noCameraAlert show];
        [noCameraAlert release];
        return;
    }

    [picker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    [picker setShowsCameraControls:YES];
    [picker setAllowsEditing:NO];
    [self presentModalViewController:picker animated:YES];

Any help is greatly appreciated! Thanks in advance!

like image 502
Mason Avatar asked Dec 17 '22 09:12

Mason


1 Answers

Your mistake is in this line

[picker setShowsCameraControls:YES];

which is where the exception is thrown, the problem is you cannot set showCameraControls to yes when you are using the album. Just comment that line out and you should be fine.

like image 168
Daniel Avatar answered Jan 11 '23 23:01

Daniel