Scenario
An app that captures an image from Front camera automatically after 3 sec countdown.
Everything is working as expected.
Code
//in viewDidLoad
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
self.imagePicker.delegate = self;
self.imagePicker.showsCameraControls = NO;
[self.imagePicker.view setFrame:kAppFrame];
[self.view addSubview:self.imagePicker.view];
[self.view bringSubviewToFront:self.imagePicker.view];
}
Problem
I have never told the ipad to use its rear device Still in certain cases the rear camera starts.
Steps to reproduce
- Hold the camera in
Landscape orientation - Click a photo (Will take you to next screen, pushed in Nav controller)
- In the next screen tilt the ipad halfway towards
face up orientation - Comeback to camera screen and you see it using rear camera.
This is a very strange behavior I am not even able to understand its cause.
It looks like I have found the solution.
just moving the entire code to
viewWillAppearfromviewDidLoadmethod.It looked like I was relying a lot on view before it appeared with a certain orientation. Putting the code in
viewWillAppearguaranteed me that the view is actually ready with its orientation set. I can now put anything on it.I know this is not the proper answer but this is what I made out of the scenario. Any modifications/correction are most welcome.