Crash while dismissing uiimagepicker - ios

This is an issue reported at crashlytics. I am getting this(I assume) when I load image picker and dismiss. I only got this once. But it got something to do with image picker or navigation controller. Does any one know the cause?
Update
Image picker camera is loaded like this.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeRight] forKey:ORIENTATION_STRING];
} else {
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:ORIENTATION_STRING];
}
self.imagePickerController = imagePickerController;
[self.navigationController presentViewController:self.imagePickerController animated:YES completion:nil];
for other source types, I am using the following code.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
popOver = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
self.imagePickerController = imagePickerController;
popOver.delegate = self;
CGRect popOverRect = sender.frame;
[popOver presentPopoverFromRect:popOverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

Add UIIMagePickerController to ContainerView. & then to view
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self addChildViewController:picker] ;
[picker didMoveToParentViewController:self] ;
[self.view addSubview:picker.view] ;
while removing pickercontroller do
[picker.view removeFromSuperview] ;
[picker removeFromParentViewController] ;

Related

imagePickerController don't go delegate method

I want to choose video from PhotosAlbum, follows this code, NOW I can choose video but can not go delegate method:
imagePickerController:didFinishPickingMediaWithInfo:
I don't know why, any help is appreciated.
UIImagePickerController*m_pPickerController = [[UIImagePickerController alloc] init];
[m_pPickerController setEditing:NO];
m_pPickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
m_pPickerController.delegate = self;
m_pPickerController.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
m_pPickerController.delegate = self;
m_pPickerController.videoQuality=UIImagePickerControllerQualityTypeLow;
[self presentViewController:m_pPickerController animated:YES completion:^{
m_pPickerController.delegate = self;
}];

Camera show black screen in ios 8

This code for capturing image one by one from camera,but after taking one image next time camera will open but with black screen(like it,s shutter close).all other ios version its working,but not working in ios 8.please tell me how can i solve it?
-(void)openCamera
{
if(![PickerHandler doesDeviceSupportMediaType:ITEM_TYPE_PHOTO])
{
[PickerHandler showNoDeviceSupportWarningForMediaType:ITEM_TYPE_PHOTO withDelegate:self];
}
else
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
[self presentViewController:picker animated:YES completion:nil];
}
}
Go to Settings > Privacy > Pictures ... and check if your app have permission.
In the code, use this to verify camera access.
- (BOOL)authorizedCameraAccess
{
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
return (status == AVAuthorizationStatusAuthorized);
}
this code is not work in simulator.
UIImagePickerController *videoScreen = [[UIImagePickerController alloc] init];
videoScreen.sourceType = UIImagePickerControllerSourceTypeCamera;
videoScreen.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
videoScreen.allowsEditing = NO;
videoScreen.delegate = self;
[self presentViewController:videoScreen animated: YES completion:NO];
Implement This method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:NO completion:NO];
}

UIImagePickerController with UIImagePickerControllerSourceTypeCamera crash EXC_BAD_ACCESS in ios7

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
This code make crash EXC_BAD_ACCESS on ios7 devices.
On iOS6 - all okay, and UIImagePickerControllerSourceTypePhotoLibrary work normal.
To work with camera
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
(NSString *) kUTTypeMovie, nil];
[self presentViewController:imagePickerController animated:YES completion:nil]; }

Display the Saved Video in iPad

I want to display the saved videos in Photo Library in popOver controller just like images.
How can i show the videos in popOver controller?
My code for Images is as follow:
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
[popoverController release];
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:CGRectMake(100, 100, 150, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[imagePicker release];
Help me to solve this problem.
Thank you,
You have to choose right mediaType:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
//here
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
imagePicker.delegate = self;

Use the UIImagePickerController on a iphone simulator

I have the method, that take photos from gallery or from the camera
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
But when i run it on the simulator, code doesnt work. And it doesnt work in picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum and picker.sourceType = UIImagePickerControllerSourceTypeCamera
Is the problem in the simulator or in the code?
Try this,
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self.navigationController presentModalViewController:picker animated:NO];
If you are creating the app for iPad. You will have to present the gallery in a popOver control.
Swift 3/4/5 verison:
if UIImagePickerController.isSourceTypeAvailable(.camera) {
picker.sourceType = .camera
}
else {
picker.sourceType = .savedPhotosAlbum // or .photoLibrary
}
Swift 2 version:
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
picker.sourceType = .Camera
}
else {
picker.sourceType = .SavedPhotosAlbum // or .PhotoLibrary
}
In simulator, you can't use cameraCaptureMode and showsCameraControls.
In simulator your picker.sourceType = UIImagePickerControllerSourceTypeCamera wont be called as there is no camera available in simulator. Also its a good practice to check whether the source type is available to avoid crashes.
#import <MobileCoreServices/UTCoreTypes.h>
….
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
imagePickerCamera.delegate = self;
imagePickerCamera.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePickerCamera.allowsEditing = YES;
imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePickerCamera animated:YES completion:nil];
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePickerAlbum =[[UIImagePickerController alloc] init];
imagePickerAlbum.delegate = self;
imagePickerAlbum.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePickerAlbum.allowsEditing = YES;
imagePickerAlbum.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerAlbum animated:YES completion:nil];
}
Similarly to the above answers, but I found this easier. Show a pop up alert if the device doesn't have a camera (like the simulator). Sam code, different usage:
//button if to take a photo
- (IBAction)takePhoto:(id)sender {
//checks if device has a camera
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"You don't have a camera for this device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
//shows above alert if there's no camera
[noCameraAlert show];
}
//otherwise, show a modal for taking a photo
else {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:NULL];
}
}

Resources