I am trying to open a UIImagePickerController
object in my application using this code:
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imgPicker.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:self.imgPicker animated:YES completion:nil];
But then the application crashes and displays the following error:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason:
'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
I also added following methods in my ViewController
class
- (BOOL) shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationMaskPortrait;
}
So, what else should I do to present this UIImagePickerController
?