UIImagePicker returns without an image - ios

Currently I'm using UIImagePickerController to allow our users to take photos within the app like so:
UIImagePickerController *picker = [UIImagePickerController new];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = #[(NSString *)kUTTypeImage];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
And I use the delegate method to get the image out to do what is needed:
-(void)imagePickerController: (UIImagePickerController *)picker
didFinishPickingMediaWithInfo: (NSDictionary<NSString *,id> *)info {
// Do stuff.
}
This works fine for 99.9% of our users but about once a week we have an odd info dictionary with no image in it. When I print the info dictionary, it looks like this every time:
{
UIImagePickerControllerMediaMetadata = {
"{MakerApple}" = {
25 = 0;
};
};
UIImagePickerControllerMediaType = "public.image";
}
As you can see there is no UIImagePickerControllerEditedImage or UIImagePickerControllerOriginalImage in that dictionary.
Anyone have any ideas on what this is, and what I might be able to do to fix it?

Related

handling captureStillImageAsynchronouslyFromConnection:completionHandler:

Ive been trying to set up a small iOS method that takes a picture automatically when user opens the app. After much research i finally found this iOS taking photo programmatically and after a little more i found this from apple https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html can someone help me get started in setting up a method for captureStillImageAsynchronouslyFromConnection:completionHandler:
i don't want any interaction from said user. thanks
Even though you seem to want to do the call asynchronously and using AVFoundation, I still recommend simply using a UIImagePickerController in this case, ex:
- (void)viewDidLoad {
[super viewDidLoad];
// If the device has a camera...
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// Create an image picker
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
imagePickerController.showsCameraControls = NO;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:^{
// And take the picture after a short delay
// to give the view and image picker time to get
// ready
[self performSelector:#selector(takepic:) withObject:imagePickerController afterDelay:2];
}];
}
}
// Automatically take the picture using the
// image picker passed in as a parameter
- (void)takepic:(UIImagePickerController*)imagePickerController {
[imagePickerController takePicture];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// ... Do whatever with the image ...
[picker dismissViewControllerAnimated:YES completion:nil];
}

iOS App crashes when user denies permission to Photos after Move & Scale in UIImagePickerController

I am using the default UIImagePickerController with allowsEditing set to YES for taking photo. When the user moves and scales the photo, the OS asks for access to 'Photos'.
The app crashes if the user denies access.
- (void)openCamera
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.editing = YES;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
And UIImagePickerControllerDelegate method goes like
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerEditedImage];
if (!image) {
image = info[UIImagePickerControllerOriginalImage];
}
self.profileImage = image;
[picker dismissViewControllerAnimated:YES completion:nil];
}
Crash message:
*** This application is not allowed to access Photo data.
I'm wondering why it should ask for access to Photos in the first place.
Any thoughts?
Use Assets Framework to test if your app is allowed to access photo data.
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if(status==ALAuthorizationStatusAuthorized) {
..your code...
}

ImagePicker loads very long for the second time

I have a problem with iOS ImagePicker. It works correctly, but when I want to take another photo the camera loads for a very long time (first time: 1-2sec, second time and later: 8-10sec). This is how I use it:
- (void)takePhoto {
_imagePicker = [UIImagePickerController new];
_imagePicker.delegate = self;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.allowsEditing = NO;
[self presentViewController:_imagePicker animated:YES completion:nil];
}
and this is how I get the image:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[_imagePickerView.imageView setImage:image];
}
I don't see there much place for bugs. Of course I implement protocols UIImagePickerControllerDelegate and UINavigationControllerDelegate.
Do you have any ideas how can I figure out what is causing this?
You may want to dismiss the UIImagePickerController after you picked an item by calling
[_imagePicker dismissViewControllerAnimated:YES completion:nil];
It should be fine, now.
Try changing your first block of code to reuse the same imagePicker you have already initialized:
- (void)takePhoto {
if(_imagePicker == nil)
_imagePicker = [UIImagePickerController new];
_imagePicker.delegate = self;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.allowsEditing = NO;
[self presentViewController:_imagePicker animated:YES completion:nil];
}

ioS7: Capture multiple images from camera and store in array

guys.
I'm trying to capture multiple images from the camera in iOS7, when I capture the first image and click in in "Use Photo", then it's store the image in a array in didFinishPickingMediaWithInfo. When the camera appear again, I see the last image in background but I can't see the camera movement. I know the camera is enabled, because it's searching faces. The code is below:
- (IBAction)openTour:(id)sender
{
_counter=0;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
imagePicker = nil;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
UIImage *image= [info objectForKey:UIImagePickerControllerEditedImage];
[ _imageArray addObject:image ];
_counter++;
if ( _counter<5 )
{
[self dismissViewControllerAnimated:NO completion:nil];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:nil];
imagePicker = nil;
}
}
else
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Does anyone know what is happening?
Thanks in advance!
Set showsCameraControls = NO;
Use cameraOverlayView property.
In the action of your camera button call takePicture method.
Keep adding UIImage objects received by the method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

UIImagePickerController in IOS7 Snapshotting a view that has not been rendered results in an empty snapshot

When I am using UIImagePickerController in IOS7.0.3 it seems to throw an error "Snapshotting a view that has not been rendered results in an empty snapshot". My code is shown below
-(void) showCamera
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
Delegate method is
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES
completion:nil];
NSString *mediaType = info[UIImagePickerControllerMediaType];
UIImage *image = nil;
if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
{
image = info [
UIImagePickerControllerOriginalImage];
}
if(picletImage != nil)
{
self.imageView.image = image;
}
}
I dont know whats wrong here but this seems to be working fine on iPad. I read through good number of articles but did not get a solution for this . I verified in instruments and seems to be a memory leak happening during camera initialization or once the picture is captured. I have been stuck with this for past 4 days , can some one can help me out as what is going wrong and also a possible solution for this.

Resources