1

App is crashing when I use UIImagePicker on iPhone, but only on iOS 7. I use the following code lines

    picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;
    picker.allowsEditing = YES;

    if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    } else {
        //[self showAlertViewWithTitle:@"Sorry" message:@"Your Device Don't Have Camera"];
    }

    [self presentViewController:picker animated:YES completion:nil];

}

The app is running on iOS 6, not in iOS 7. I am new on this site, please help.

Deepesh
  • 8,065
  • 3
  • 28
  • 45
Pravin
  • 44
  • 9

3 Answers3

1

The UIImagePickerController presenting in Potratin Mode Only in iPhone. And i found one more bug in to your Code that you are using picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary while isCameraDeviceAvailable that wrong:-

you should code like:-

if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
       picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                 [self presentViewController:picker animated:YES completion:nil];
    } else {
         picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                 [self presentViewController:picker animated:YES completion:nil];       
    }

and in to your ViewController shouldAutorotate change to NO instead of YES

Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
1

In you ViewController.m file before start @implementation write following code

@interface NonRotatingUIImagePickerController : UIImagePickerController

@end

@implementation NonRotatingUIImagePickerController

- (BOOL)shouldAutorotate
{
    return NO;
}

@end

Where you want to create a object of Image Picker write following code

UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self; 
    [self presentModalViewController:picker animated:YES];
user1673099
  • 3,293
  • 7
  • 26
  • 57
0

ok if that is the case try this out...

add this to your ViewController

- (NSUInteger) supportedInterfaceOrientations
{
     //Because your app is only landscape, your view controller for the view in your
     // popover needs to support only landscape
     return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Community
  • 1
  • 1
Raon
  • 1,266
  • 3
  • 12
  • 25
  • I think this is deprecated now. Only Navigation controllers are supposed to have supportedInterfaceOrientations method – ShayanK Oct 29 '13 at 18:04