0
votes

My app is universal. iPad is landscape only (left or right); iPhone is portrait only.

Everything's working fine for iPhone as coded, but I'm getting the following error on iPad when attempting to present UIImagePickerController.

Error

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

Here's my setup...

Info.plist (iPad Supported Orientations)

<array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

App Delegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if(isPad()){
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

View Controller Presenting Picker

- (NSUInteger) supportedInterfaceOrientations
{
    if(isPad()){
        return UIInterfaceOrientationMaskLandscape;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

-(BOOL)shouldAutorotate{
    return NO;
}

-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
if(isPad()){
    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}else{
    return UIInterfaceOrientationPortrait;
}

}

UIImagePickerController Category

- (NSUInteger) supportedInterfaceOrientations
{
    if(isPad()){
        return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

-(BOOL)shouldAutorotate{
    return NO;
}

-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    if(isPad()){
        return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
    }else{
        return UIInterfaceOrientationPortrait;
    }
}

Worth Noting

The UIImagePicker (in iPad) is being presented from a view controller presented by a UIPopoverController

3

3 Answers

0
votes

In UIImagePickerController Category use

-(NSUInteger)supportedInterfaceOrientations {  
    if(isPad()){
        return UIInterfaceOrientationMaskLandscape;
    }
    else{
        return UIInterfaceOrientationMaskPortrait;
    }
} 
0
votes

Turns out you MUST present the UIImagePickerController in a popover on iPad.

0
votes

The UIImagePickerController class supports portrait mode only. See Apple docs