16

*My view is in land scape mode i am saving image and i want that image back for that i my code is below and i am geting error "Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'" * what can i do for iphone?

        `- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

         [self dismissModalViewControllerAnimated:YES];
         [picker release];

              }
             - (void)imagePickerController:(UIImagePickerController *)picker 

                didFinishPickingMediaWithInfo:(NSDictionary *)info {

            [picker dismissModalViewControllerAnimated:NO];

                imageDoodle.image = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];

                 }

               -(IBAction)loadfromalbumclicked:(id)sender

                 {

                UIImagePickerController * picker = [[UIImagePickerController alloc] init];

                picker.delegate = self;

                 picker.allowsEditing=NO;

        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

               // self.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;

              [self presentModalViewController:picker animated:YES];
               }

              -(IBAction)savePrint{
//Save image to iOS Photo Library

                 UIImageWriteToSavedPhotosAlbum(imageDoodle.image, nil, nil, nil);
//Create message to explain image is saved to Photos app library
                 UIAlertView *savedAlert = [[UIAlertView alloc] initWithTitle:@"Saved"  

                message:@"Your picture has been saved to the photo library, view it in the 

               Photos app." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
//Display message alert
             [savedAlert show];
              }`
virantporwal
  • 989
  • 2
  • 6
  • 26

7 Answers7

16

try setting shouldAutoRotate to NO and see if it works.

You can use shouldAutoRotate and supportedInterfaceOrientations methods in iOS 6.0 or later, instead of the (deprecated) shouldAutoRotateToInterfaceOrientation method.

Something like this -

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}


- (BOOL) shouldAutorotate {
    return YES;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}
vshall
  • 619
  • 7
  • 26
6

You supporting only limited orientations either landscape or portrait. But you calling different orientation in your view controller.

You can see the following image with supported Orientation. It support only landscape right and landscape left.So if i call portrait it will show the error as like you. So if you want to support both orientation then change it in the summary.

enter image description here

See this answer for more detail. Hope it helps.

EDIT

So you have to put this code in your viewcontroller

  - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |   UIInterfaceOrientationMaskLandscapeRight;
 }
Community
  • 1
  • 1
vinothp
  • 9,939
  • 19
  • 61
  • 103
5

This error is thrown if there's a mismatch between the supported interface orientations in the plist and the ones returned by -(NSUInteger)supportedInterfaceOrientations

Keep in mind that that the NSUInteger returned by the supportedInterfaceOrientations must be a UIInterfaceOrientationMask, note the -MASK-, I once made the mistake of simply returning a UIInterfaceOrientation i.s.o. the ...Mask value (that's autocomplete for you)

e.g.

- (NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    // and NOT UIInterfaceOrientationPortrait;
}
Pieter
  • 17,435
  • 8
  • 50
  • 89
  • 3
    I'm embarrassed to say that's what I did, too. I even knew I needed the MASK constant, and somehow I just didn't see that autocomplete gave me something else. – bugloaf Mar 14 '14 at 15:38
4

Note : If you use UIImagePickerController or UIPopoverController and these error occurs then these below solution is damn good.

Also these error comes in iOS 6.0 only

Create a new one UIImagePickerController's category and add

@implementation UIImagePickerController(custom)

  -(BOOL)shouldAutorotate
  {
    return NO;
  }
@end

That's works for me.

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • hi price its not working in ios7 and returns the plain white picker view without any cancel or done button. have you any idea to solve that. Thanks – Ilesh P Jan 13 '15 at 04:58
1

If you are using cocos2d v2.1, you can try this for Portrait.

    -(NSUInteger)supportedInterfaceOrientations {

    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationMaskPortrait;

    // iPad only
    return UIInterfaceOrientationMaskPortrait;
}

// Supported orientations. Customize it for your own needs
// Only valid on iOS 4 / 5. NOT VALID for iOS 6.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    // iPad only
    // iPhone only
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

The supported Orientations and auto rotate Orientations should be the same.

elroy
  • 21
  • 2
0

For iOS 6.0, if your app only support landscape mode, when you pop up the UIImagePickerController, it will crash.

My solution is add below category to UIImagePickerController:

@interface UIImagePickerController (oritation)

@end

@implementation UIImagePickerController (oritation)

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

@end
ZYiOS
  • 5,204
  • 3
  • 39
  • 45
0

I had the same error, it could be one or more of the following return conflicting orientations:

  • Check your -Info.plist, for the key "supported interface orientations"
  • Check your Summary pane, by clicking on your app from the project navigator.
  • As others have mentioned, check what supportedInterfaceOrientations method is returning.

I solved mine by explicitly defining separate "supported interface orientations (iPad)" and "supported interface orientations (iPhone)" keys in the -Info.plist, as I wanted different orientations for different devices.

Good luck!

Joel Balmer
  • 1,428
  • 2
  • 19
  • 21