3

enter image description hereI am working on app which is totally in Landscape mode. On one of the view, I need to open the camera(UIImagePickerController) with overlay view. But When I click the button to open camera it get crashed with this issue i.e. reason:

'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

I also put this line in viewcontroller but no effect.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

Please give me some idea to make it working.

Sudha Tiwari
  • 2,499
  • 26
  • 50

1 Answers1

1

If you are using a UINavigationController as base view controller , that code snippet you provided simply doesn't work. Because you are adding that code to a UIViewController but it's already embeded in a UINavigationController.

To overcome this issue, you must create a subclass of UINavigationController and add that landscape related code to that subclass. Then assign this subclass to your Storyboard's base Navigation Controller. Then this issue will be solved.

This is your navigation controller sub class' .h file

@interface YourCustomNavigationController : UINavigationController
@end

And add this to your navigation controller subclass' .m file

- (BOOL)shouldAutorotate
{
    //returns true if want to allow orientation change
    return YES ;  
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

And make sure to assign this class to your base Navigation controller using interface builder's identity inspector.

Project settings,

enter image description here

EDIT:

You can present a UIImagePickerController in landscape mode. Regardless of what documentation says, you can actually subclass it and can override it's functionality to work on landscape mode. (atleast its working on iOS 7)

To do this, you must create a subclass of UIImagePickerController and add above lines to that subclass. Project settings must be same as screenshot (atleast one landscape mode and one portrait mode must be ticked).

Then use that subclassed ImagePicker controller when you presenting the camera. It would successfully load camera in landscape mode. But standard camera controls will be misaligned and messed up. So better to hide defaultControlls (picker.showsCameraControls = NO;) just like you've done and use an overlay view instead.

Rukshan
  • 7,902
  • 6
  • 43
  • 61
  • not resolved. Giving same issue i.e. Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES' – Sudha Tiwari Mar 04 '14 at 11:58
  • 1
    The reason is you have only ticked Landscape left in your project properties. Tick all 4 options, (may be exclude upside down). Then it will not crash. Because you have specifically mentioned to return `UIInterfaceOrientationLandscapeLeft` from your `UINavigationController` subclass, it will stay that way (althugh project settings says otherwise) – Rukshan Mar 04 '14 at 12:01
  • Selected both modes but still it is showing same issue – Sudha Tiwari Mar 04 '14 at 12:06
  • edited my answer, make sure whether you are doing the same thing. – Rukshan Mar 04 '14 at 12:10
  • Did the same but no effect. – Sudha Tiwari Mar 04 '14 at 12:11
  • the same one UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES' – Sudha Tiwari Mar 04 '14 at 12:14
  • It's impossible to get that error if you ticked all 4 device orientations from Project Settings (see screenshot). Because when you select all 4, you will always have 'common' orientations – Rukshan Mar 04 '14 at 12:16
  • I have selected all the orientation – Sudha Tiwari Mar 04 '14 at 12:17
  • Make sure you are not overriding `supportedInterfaceOrientations` from somewhere else othr than this subclass of UINavigationController – Rukshan Mar 04 '14 at 12:17
  • Crash removed but camera opens in portrait mode. – Sudha Tiwari Mar 04 '14 at 12:19
  • make sure you have assigned your subclass to your existing nav controller in storyboard, and make sure camera is presented from nav controller by a push (not modal) – Rukshan Mar 04 '14 at 12:22
  • Now giving this error (Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported') – Sudha Tiwari Mar 04 '14 at 12:27
  • Why are you pushing a navigation controller? You should push a UIViewController with the camera view. – Rukshan Mar 04 '14 at 12:38
  • all the required code is here, anyways how can i send you code – Rukshan Mar 04 '14 at 12:44
  • check http://pastebin.com/W9G53X9z I have added the code which called during button click. Have I done something wrong? – Sudha Tiwari Mar 04 '14 at 12:48
  • I see, since you are using ImagePickerController and it inherits from navigation controller so you can not push. Give me some time I will test this issue – Rukshan Mar 04 '14 at 18:28
  • can you send me the sample for opening the image picker in landscape mode. – Sudha Tiwari Mar 05 '14 at 05:39