Вопрос

I am working on a universal app, when trying to select a photo from the devices library on

the iPad I get a SIGABRT error, but it works fine on the iPhone

   picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
   [self presentViewController:picker animated:YES completion:nil];  //the culprit, why?

Thanks for any help in advance!

Это было полезно?

Решение

Please read the docs for UIImagePickerViewController:

The table indicates that on iPad, if you specify a source type of UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeSavedPhotosAlbum, you must present the image picker using a popover controller, as described in “Presenting and Dismissing the Popover” in UIPopoverController Class Reference. If you attempt to present an image picker modally (full-screen) for choosing among saved pictures and movies, the system raises an exception.

On iPad, if you specify a source type of UIImagePickerControllerSourceTypeCamera, you can present the image picker modally (full-screen) or by using a popover. However, Apple recommends that you present the camera interface only full-screen.

You must use a UIPopoverController to present the image picker for the photo library on the iPad.

Другие советы

        // While showing UIImagePickerController in iPad, you must do it using UIPopoverController as follow 


        // Declare UIPopoverController and present your UIImagePickerController using it
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        [imagePicker setDelegate:self];
        [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [imagePicker setAllowsEditing:YES];

        popOverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
        [popOverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top