Search code examples
iosobjective-cipaduiimagepickercontrolleruipopovercontroller

UIImagePickerController in UIPopoverController is showing as blank white view


I'm currently writing an iOS app wherein I want to let the user pick an image from their photo library. I don't want them to be able to take a new photo or edit the existing one, but that's unimportant right now. Since this is an iPad app, I have to show the UIImagePickerController view in a popover view (or an exception is thrown, etc.). This is the code I am currently using to try to achieve that:

- (void)viewDidLoad{
    [super viewDidLoad];
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
        _picker = [[UIImagePickerController alloc] initWithRootViewController:self];
        _picker.delegate = self;
    }else{
        [[[UIAlertView alloc] initWithTitle:@"goto fail;" message:nil delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil] show];
    }
    self.view.backgroundColor = [UIColor purpleColor];
}

- (void)viewDidAppear:(BOOL)animated{
    popoverController = [[UIPopoverController alloc] initWithContentViewController:_picker];
    [popoverController presentPopoverFromRect:(CGRect){CGPointZero, {1, 1}} inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated];
    [super viewDidAppear:animated];
}

I expect this to show an image picker view in a popover, obviously. Instead, I get this: This code is running on a real iPad, not in the simulator. I have never been prompted to grant access to my photos, and there is no entry for the app in the photo area of the privacy settings of Preferences.app. I am testing this on an iPad 4 (which has a camera), and cannot test in the simulator, as it is having issues at the moment. I'm not really sure where the issue could be coming from - it's quite perplexing.


Solution

  • Also you should specify UIImagePicker's sourceType.

    _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    UPDATE

    Initialise picker this way:

    _picker = [[UIImagePickerController alloc] init];