5

I have a landscape only app and whenever I access the Photo library , app would crash (because UIImagePickerViewController is trying to load in portrait mode). App works fine in iOS 5 and 6.

I'm getting following error,

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

*** First throw call stack:
(0x2ff7ae8b 0x3a2746c7 0x2ff7adcd 0x3277337d 0x3277a4c5 0x3277a47b 0x327795b3 0x326fff3d 0x326ffd19 0x326ff609 0x326ff467 0x3270c153 0x3270bbd3 0x327b7f67 0x327b7d83 0x327afdf3 0x327af279 0x327aefe9 0x327aef7d 0x32700533 0x32387f43 0x32383767 0x323835f9 0x3238300d 0x32382e1f 0x3237cb4d 0x2ff45f71 0x2ff438ff 0x2ff43c4b 0x2feae541 0x2feae323 0x34be52eb 0x327651e5 0x8c439 0x8c3c0)

`libc++abi.dylib:` terminating with uncaught exception of type `NSException`

When I enable portrait mode everything works as usual but I don't want to enable portrait mode. What is the workaround for this?

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
Rukshan
  • 7,902
  • 6
  • 43
  • 61
  • possible duplicate of [iOS7 iPad Landscape only app, using UIImagePickerController](http://stackoverflow.com/questions/20468335/ios7-ipad-landscape-only-app-using-uiimagepickercontroller) – Peter Lapisu Feb 17 '14 at 18:27

4 Answers4

8

yes, I have similar issue in an app

you can add Portrait mode support to app but limit all other views to only support landscape, mode, then image picker will work

UIImagePickerViewController only works on portrait mode

to restrict other views only support landscape mode, override - (NSUInteger)supportedInterfaceOrientations in your view controller

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}
Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
lanbo
  • 1,678
  • 12
  • 12
  • How did you limit all other views to only support landscape? I tried every possible way but it still rotates to portrait when add portrait mode support in plist. – Rukshan Sep 25 '13 at 08:41
  • add codes to your view controller - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscape; } – lanbo Sep 25 '13 at 08:45
  • 3
    In my case this didn't work because My root view controller was a navigation controller. So I had to subclass the navigation controller with those methods. Then it worked! Thank you! :) – Rukshan Sep 25 '13 at 09:55
1

Add below code snippet in appdelegate.m file. This will resolve the above issue.

 -(NSUInteger)application:(UIApplication *)application 
supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
     {
         return UIInterfaceOrientationMaskAll;
     }
     else
     {
         return UIInterfaceOrientationMaskAllButUpsideDown;
     }
}
Anooj VM
  • 2,593
  • 22
  • 19
0

The CGAffineTransform property of UIImagePickerController can be used to get the camera in desired orientation. imagePicker.cameraViewTransform=CGAffineTransformRotate(yourimagePicker.cameraViewTransform, M_PI/2);

Alternatively you can also use CGAffineTransformScale to apply custom size to your camera.

Vacca
  • 1,219
  • 16
  • 26
0

You can simply present the imagePicker using

ImagePickerController *imagePickerController=[[ImagePickerController alloc]init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
abhimuralidharan
  • 5,752
  • 5
  • 46
  • 70