开发者

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
                                                      c开发者_JAVA技巧ancelButtonTitle:@"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!


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.


I think the issue is that you're setting the sourceType to UIImagePickerControllerSourceTypeSavedPhotosAlbum regardless of which sourceType is supported.

i.e. The following line should be conditional;

[picker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];

Instead, put in a condition or two, and if the UIImagePickerControllerSourceTypeSavedPhotosAlbum exists, then only set the sourceType to this one. Else, if the UIImagePickerControllerSourceTypeCamera exists, set the sourceType to that one.

Also, I guess [picker setShowsCameraControls:YES]; should be done for the UIImagePickerControllerSourceTypeCamera sourceType only.

The error you're getting is suggesting that UIImagePickerControllerSourceTypeSavedPhotosAlbum is not supported, so try working it out in this manner.


What you need to do is... Change your if condition in else if then or.. when

if([isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{

[picker setShowsCameraControls:NO];
}
else
{
[picker setShowsCameraControls:YES];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜