lundi 26 janvier 2015

UIImagePicker only works with front camera on iPhone 6 plus

Using the following code:



- (void) viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

if (!self.alreadyAppeared) {

[self performSelector:@selector(showCamera) withObject:nil afterDelay:0.3];
}

}

-(void)showCamera
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.delegate = self;

[self presentViewController: picker animated:YES completion:NULL];
}


my app works perfectly. However if I change the



picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;


to



picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;


I lose the image. The following code is how I capture the image and set an imageview within my app. I use a Nav controller to return to the app:



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
self.cf.imageView.image = chosenImage;

NSLog(@"%@",chosenImage);
[picker dismissViewControllerAnimated:YES completion:NULL];

// pop back to previous controller
NSArray *myControllers = self.nc.viewControllers;
int previous = (int)myControllers.count - 2;
UIViewController *previousController = [myControllers objectAtIndex:previous];

[self.nc popToViewController:previousController animated:YES];

}


Again, this works just fine on my iPad and it works just fine using the front camera. Even when using the rear camera the chosen image (that I log) appears correct. Does anybody have any idea why the rear camera setting would have such an effect?


One other item: I get this very irritating message that has about 1,000 different explanations none of which get rid of the message:


Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.




Aucun commentaire:

Enregistrer un commentaire