The iPod Touch (5th gen) has both a front and rear camera so why does my app crash when i try to present a UIImagePickerController with sourceType: UIImagePickerControllerSourceTypeCamera
- (void)openImagePickerType:(NSString *)type
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
if([type isEqualToString:kImagePickerCameraString])
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
if([type isEqualToString:kImagePickerLibraryString])
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
if(IS_IPAD && imagePicker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary){
DLog(@"show popopver image picker");
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:self.cameraButton.bounds inView:self.cameraButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popover = popover;
}else{
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
First, You should always validate if the resource is available or not, try using:
From the official docs:
Second, I don't see clearly when this part should be executed:
You should specify something like this:
type var
when you can always use directlyUIImagePickerControllerSourceType
as you var's type