1

I am having an app which is only in Landscape Mode. In my app I am opening the Camera from one of my views. It is working well for my iPad but on iPhone it crashes. It is working well in iOS 6 but the app crashes for iOS 7 and only for iPhone.

Below is my code.

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{

    ipc=[[UIImagePickerController alloc] init ];
    ipc.delegate=self;
    ipc.sourceType=UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:ipc animated:YES completion:nil];
} 
else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Desc" message:@"Camera capture is not supported in this device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}

How to solve this issue?

It crashes when I select to capture from camera. It doesn't crash from the above code but after that it crashes with below error.

I am getting this error:

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

And my app crashes.

My orientation code on this view.

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Manthan
  • 3,856
  • 1
  • 27
  • 58

5 Answers5

2

I am also getting same problem previously. I followed the steps. Please try this and let me know if your facing same problem. check mark enter image description here

Step 1: check in appdelegate.m

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

step 2: In your view controller

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
    return YES;
    return NO;
}

Step 3: your view controller

-(IBAction)TakePhoto:(id)sender{

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
       UIImagePickerController*    imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
        [self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:nil];//add to view as per requirement
    }
    else
    {
        UIAlertView *noCam = [[UIAlertView alloc] initWithTitle:@"Notification" message:@"There is No Camera Fecility" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [noCam show];
    }
}
Meet Doshi
  • 4,241
  • 10
  • 40
  • 81
Kittu
  • 1,577
  • 1
  • 9
  • 12
  • I solved my problem with the above link I mentioned. Are you having some problem with your code? Then I can help you. – Manthan May 21 '14 at 09:29
1

Does the crash occur on launching the UIImagePickerController or after taking an image with the camera? I tried out your code on an iPod running iOS7 and it works fine. The issue could be somewhere else. I've seen crashes happening with the UIImagePickerController due to memory usage so that could be something for you to check. Also while we're at it, presentModalViewController:animated: is deprecated since iOS6.0. You need to use presentViewController:animated:completion: instead. Also seeing the release statement for your UIAlertView, it looks like you're not using ARC so memory usage is definitely something I would look into. Hope this helps.

EDIT: From the UIImagePickerController documentation
Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

batman
  • 1,937
  • 2
  • 22
  • 41
  • I've edited my answer. The picker only supports Portrait while your app doesn't. – batman May 21 '14 at 05:31
  • What you could do is create a UIView and add the UIImagePickerView as a subview to it. There are several posts that show how to do this or you could use the AVFoundation framework as described here: http://stackoverflow.com/a/11232352/1113598 – batman May 21 '14 at 05:38
  • Yes, that is right but what problem is that then i gave my app all supported orientations and lock the orientation to portrait for camera views only and its working fine but for my first view only it shows in portrait mode. All views are locked but only my first VC shows in portrait mode. – Manthan May 21 '14 at 05:38
  • http://stackoverflow.com/questions/20468335/ios7-ipad-landscape-only-app-using-uiimagepickercontroller look at this question and can you please tell me which category i need to create from my project? – Manthan May 21 '14 at 05:40
  • You will need to implement step 1. In step 2, you will need to check for supported orientations and return them. Step 3 will be added as is since you need your picker to launch in landscape. – batman May 21 '14 at 05:43
  • Yes, I did that and it worked for me.Thanks for your help and giving me some idea. Thanks. +1 for your help. – Manthan May 21 '14 at 06:22
0

Try this code, it works on my old app.

-(BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

May be you want to check this: GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation

Community
  • 1
  • 1
Ricky
  • 10,485
  • 6
  • 36
  • 49
0

I found my solution from the link iOS7 iPad Landscape only app, using UIImagePickerController.

It worked for me like a charm.

Hope it help someone else also.

Thanks for your help people.

Community
  • 1
  • 1
Manthan
  • 3,856
  • 1
  • 27
  • 58
0

I had inherited the UIImagePickerController, and override the tow methods to supported landscape (or you can make a category):

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

And add the Portrait (bottom home button), Landscape (left home button), Landscape (right home button) in Supported interface orientations(iPad). Supported interface orientations(iPad)

Here, must add the Portrait (bottom home button) value, because the UIImagePickerController just supports portrait mode only, so we need to add the portrait mode, otherwise it will raise an exception.

likid1412
  • 963
  • 8
  • 15