为什么UIImagePickerControllerSourceTypePhotoLibrary不允许用户选择相册?

时间:2012-10-24 11:54:06

标签: iphone objective-c uiimagepickercontroller

我目前正在为iPad开发一个iPad应用程序,我将UIPopOverController与UIImagePickerController结合使用,让用户从iPad中选择一个图像(使用sourceType UIImagePickerControllerSourceTypeSavedPhotosAlbum)。这很好,并且符合预期,但它只允许客户端显然浏览SavedPhotos相册。如果我更改选择器以使用UIImagePickerControllerSourceTypePhotoLibrary,该窗口仍将显示其专辑,但它将是静态的(意味着我可以滚动,但我无法选择专辑,当我向下或向上滚动时,视图将只会弹出如果我再次点击屏幕,请回来。)

PhotoLibrary是否需要额外的设置才能正常工作?我尝试了很多方法,但我在这里都运气不好。

设置是一个OpenGL视图,我在其上使用UIImagePicker生成UIPopOverController。为清楚起见,这是代码:

-(void)showPicker
{
    if(![pController isPopoverVisible])
    {
        [pController presentPopoverFromRect:CGRectMake(50,100,200,300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
    }
    else
    { 
        pController dismissPopoverAnimated:YES];
    }
}
-(void)awakeFromNib
{
    picker = [[UIImagePickerController alloc] init];

    pController = [[UIPopoverController alloc] initWithContentViewController:picker];

    // Code works properly if I only set it to UIImagePickerControllerSourceTypeSavedPhotosAlbum
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    else if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) picker.sourceType =UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    else { NSLog(@"Error: Could not pick appropriate sourceType"); }

    picker.mediaTypes = [NSArray arrayWithObjects:(NSString*)kUTTypeImage, nil];
    picker.delegate = self;
    pController.delegate = self;
    picker.allowsEditing=NO;
}

1 个答案:

答案 0 :(得分:0)

您是否正在使用 iOS6 ? 我知道在设置/隐私中,您必须允许您的应用在相册中查看。