Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIIMagePickerController crash on dismissing on iPad ios 6.0

I work on iPad 4 with iOS 6.0.

I have a ViewController (MyPickerController) with the following init:

- (id)init
{
    self = [super init];
    if (self) {
        _picker = [[UIImagePickerController alloc] init];
        _picker.delegate = self;
        _picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self.view addSubview:_picker.view];
    }
    return self;
}

I implement the following UIPickerControllerDelegate method to dimiss MyPickerController:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

Well, I have another view controller showed modally in FormSheetStyle and when I tap on a button I want to show MyPickerController with the following code:

MyPickerController * pickerVC = [[MyPickerController alloc] init];
[self presentViewController:pickerVC animated:YES completion:nil];

In my AppDelegate i Have the following totation method:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    
    return (NSUInteger)[application supportedInterfaceOrientationsForWindow:window] | (1<<UIInterfaceOrientationPortrait);
    
}

When I tap on cancel button of UIIMagePicker into MyPickerController, the application crashes with the following error:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!

Reading related questions on stackoverflow, I create also the follwing UIImagePickerController category:

@implementation UIImagePickerController (NonRotating)

- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

@end

Thank you!

like image 225
MaTTP Avatar asked Jan 18 '13 10:01

MaTTP


1 Answers

Try doing this..

If your view controller is inside a UINavigationController, you should use this category for the navigationcontroller:

@implementation UINavigationController (autorotate)

- (NSUInteger)supportedInterfaceOrientations{
      return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
      return UIInterfaceOrientationMaskPortrait;
}


@end
like image 162
mayuur Avatar answered Oct 12 '22 23:10

mayuur