Jason
Jason

Reputation: 168

Ipad Photo Picker

I am trying to get the IPAD to choose a photo from the photo album

            pickerController = [ [ UIImagePickerController alloc ] init ] ;
            pickerController.delegate   = self ;
            pickerController.editing    = NO ;
            pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

            [ self presentViewController : pickerController animated : YES completion : nil ] ;

The app keeps crashing when I use it on iPad, but works fine on iPhone.

Upvotes: 1

Views: 1503

Answers (1)

Jim Range
Jim Range

Reputation: 523

This one got me before too. On the iPad if you specify a source type of UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeSavedPhotoAlbum you need to present the image picker controller using a popover controller. If you try to present it modally, like you are doing, you will get an exception.

Not 100% required, but it's also a good idea to use the test to see what source types are available.

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]

The source types are:

  • UIImagePickerControllerSourceTypePhotoLibrary
  • UIImagePickerControllerSourceTypeSavedPhotosAlbum
  • UIImagePickerControllerSourceTypeCamera

This is how I solved this issue to test if it is an iPad or not.

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){

    UIPopoverController* popOverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
    [popOverController presentPopoverFromRect:selectVideoToViewButton.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}else {
    [self presentModalViewController:self.imagePickerController animated:YES];
}

Upvotes: 6

Related Questions