How to handle a system alert for iOS?

I have an application in which I use the UIImagePickerController to use the built-in camer inorder for clicks, but when the photo gallery on the device is full. I get a warning message saying: "Can not Take Photo - There is not enough free space to store the photo. You can manage your storage in the settings." I am given two options: click the "Finish" or "Settings" button. Clicking on any of them does nothing, and the application completely freezes.

This is what I get from console logs

Not enough space to take a picture. Available space is 0 

Code for selection

 UIImagePickerController *mediaPicker = [[UIImagePickerController alloc] init]; mediaPicker.sourceType = UIImagePickerControllerSourceTypeCamera; mediaPicker.delegate=self; mediaPicker.sourceType=UIImagePickerControllerSourceTypeCamera; [self presentModalViewController:mediaPicker animated:YES]; 

I have already implemented and tried all the delegates and did not call a single delegate.

Is there any way to implement something where I can use the listener to detect when this error occurs and return the user to the previous screen?

+7
source share
2 answers

It looks like your device has run out of memory, the system has sent many Notifications from memory, and your application has also received one. As a result, your application released the UIViewController , initially launching the UIImagePickerController.

Now when you close the imagePicker button with the Done / Settings button, control returns back to your application. The old UIViewController no longer exists, and you have not implemented the code to recreate it from scratch in such situations. The device appears to be frozen, but only because the user interface has not been redrawn by your application. Otherwise, the application works fine.

You can verify this case by running the didReceiveMemoryWarning method in every UIViewController and logging if it called:

 - (void)didReceiveMemoryWarning { NSLog(@"%@", [self description]); [super didReceiveMemoryWarning]; } 

One of my favorite mistakes. Easy to miss :)

+2
source

This sounds like a bug in iOS, and you should file the radar here .

+1
source

All Articles