Crash on presenting UIImagePickerController under iOS 6.0

两盒软妹~` 提交于 2019-11-26 21:42:20

iOS 6.1 - fixed

As of iOS 6.1, this no longer occurs, it is very important to follow my tips in order to avoid a crash under iOS 6.0.x, the below still applies to that.


iOS 6.0.x workaround

This is in actual fact a bug in iOS 6.0, this should be fixed in future iOS releases.

An engineer from Apple has explained this bug and a workaround here: https://devforums.apple.com/message/731764

This is happening because the Application wants landscape orientation only but some Cocoa Touch View Controllers require strictly Portrait orientation which is the error - not that they should be requiring more then Portrait but their interpretation of the Applications requirements.

An example of this can be the following:

iPad app supporting landscape only displays a UIImagePickerController via a UIPopoverController. The UIImagePickerController requires Portrait orientation, but the app is forcing landscape only. Error and... crash

Other frameworks that have been reported as problematic include the Game Center login view controller.

The workaround is pretty simple but not ideal... You keep the correct orientations declared in your info.plist/project info pane, but in the Application Delegate class you declare that you allow all orientations.

Now each View Controller you add to the window must specify itself that it can only be Landscape. Please check the link for more details.


I cannot stress how much you should not be subclassing UIImagePickerController as the accepted solution is insisting you do.

The important thing here is "This class is intended to be used as-is and does not support subclassing."


In my case I added this to my application's delegate (I have a landscape only app), this tells the image picker it can display, because portrait is supported:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationMaskAll;
}

And then in my view controller which happened to be a UINavigationController, I included a category with the following:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

Now my app doesn't rotate, and the image picker asks the delegate if it can display as portrait and it gets told that's okay. So all plays out well.

I had a similar issue, but in an iPad landscape app. I was presenting the image picker in a popover. It crashed under iOS 6. The error suggested that the picker wanted portrait, but the app only offered landscape views, and ... importantly ... the picker's shouldRotate was returning YES.

I added this to my ViewControllerClass.m that is creating the picker

@interface NonRotatingUIImagePickerController : UIImagePickerController

@end

@implementation NonRotatingUIImagePickerController

- (BOOL)shouldAutorotate
{
    return NO;
}

@end

and then used that class instead

UIImagePickerController *imagePicker = [[NonRotatingUIImagePickerController alloc] init];
[myPopoverController setContentViewController:imagePicker animated:YES];

That solved the problem for me. Your situation is a bit different, but it sounds like fundamentally the same error.

While subclassing UIImagePickerController works, a category is a better solution:

    @implementation UIImagePickerController (NonRotating)

    - (BOOL)shouldAutorotate
    {
        return NO;
    }

    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }

    @end

Reporting from iOS 7.1:

In addition to what the above answers specify it seems that you have to absolutely enable portrait modes in the info.plist.

Without this none of the above code/fixes worked for me.

ANIL.MUNDURU
-(NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscape;
}

Will fix the issue but from iOs7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!