UIImagePickerController in iOS 6 not working properly

I have a very strange behavior:

  • in iOS 5 I present the UIImagePickerController as follows:

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:imagePicker animated:YES];

now in iOS 6 it crashes. I resolved the failure by writing a category on the UIImagePickerController :

 @implementation UIImagePickerController (NonRotating) - (BOOL)shouldAutorotate { return NO; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskPortrait; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } @end 

The problem is that now the UIImagePickerController does not rotate and displays up. Moreover, when I click the Cancel button and the collector is fired, the application crashes again.

  • If I use the UIImagePickerController inside a UIPopoverController , everything works fine (this is because the popover does not rotate), but when I reject popover ALL the view controller in my application stops responding to rotation events , and this means that the whole application is locked in this orientation. To restore the correct behavior, I need to close the application from the background and reopen.

This is the code I use to display popover

 _cameraPopoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker]; [_cameraPopoverController presentPopoverFromRect:_takeFromCamera.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

This problem is driving me crazy!

+1
source share
2 answers

What is your type of source of choice? Photo library / album or camera roll?

Assuming you are using Photo Library / Album source on an iPad, you MUST use popover:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html (see overview, paragraph 4)

full screen display is not supported.

About another problem (after popOver rejects, another VC stops spinning) check that you have a STRONG link to your popover (strong property). Paste the code you use to represent the popover.

0
source

While I do not recommend using the category to override the default behavior for selecting an image, there is an error in the implementation that causes the mentioned crash:

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskPortrait; ~~~~ } 

The return value should not be an orientation mask, it should be an orientation, for example. UIInterfaceOrientationPortrait.

0
source

Source: https://habr.com/ru/post/1502374/