Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera App doesn't dismiss when "Not enough available storage..." on iPhone

I have an app which let's you take a picture with the iphone camera. Everything works like a charm but when testing on a new device which happened not to have enough storage available, the camera app didn't dismiss.

So basically I open the image picker with source camera, I get a popup that says "There is not enough available storage to take a photo..." and then when I press OK, I am at the Camera app, with the shutter closed, and both the "take photo" and "cancel" buttons grayed out. From this point on the only thing I can do is to kill the app as there is no way to leave this screen.

In my code I call the camera with something like:

UIImagePickerController * photoPicker= [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:photoPicker.sourceType]) {
    [self presentModalViewController:photoPicker animated:YES];
}

The object which call this is of course a UIImagePickerControllerDelegate and I implement both delegate methods (both respond correctly to success and cancel events):

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

This "no space available" behaviour doesn't fall on any of the delegate methods, so I am unable to programatically dismiss the camera app.

Any thoughts?

EDIT:

When trying to run the app in the simulator where the Camera is not available I noticed the App crashing because that source was unavailable. I found out that simply assigning an unavailable sourceType to the photoPicker, even before calling the controller, would crash the app, so I changed the code to the following:

UIImagePickerController * photoPicker= [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}else{
    return;
}
[self presentModalViewController:photoPicker animated:YES];

This still doesn't fix my problem, but it's an interesting finding.

like image 528
manecosta Avatar asked Dec 18 '12 18:12

manecosta


1 Answers

The problem is not with camera, but the rest of the application: camera has trickered didReceiveMemoryWarningand thus "killed" the view, where you were trying to return to. It's just not there any more.

The fix is to implement UIViewController's viewDidLoad, viewDidUnload, viewWillDisappear, viewWillAppear etc. and make sure your app can handle out of memory situation caused by Camera and initialize everything needed, when Camera disappears.

like image 144
JOM Avatar answered Oct 17 '22 07:10

JOM