1

当我尝试从 xcode 4.5 调用相册时,应用程序崩溃。注意:我将应用程序方向设置为横向模式。

UIImagePickerController *picker=nil;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
    picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    picker.allowsEditing = NO;
    picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:
            UIImagePickerControllerSourceTypeSavedPhotosAlbum];

}

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) {
    [self presentViewController:picker animated:YES completion:nil];
}
4

1 回答 1

1

您的逻辑中的一个错误是,如果isSourceTypeAvailable在 iPhone 上返回 NO,您将尝试提供一个nil.

于 2012-10-15T12:30:49.100 回答