Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle a system alert message for iOS?

I have an app where i am using UIImagePickerController to use the native camer inorder to click pictures but the when the photo gallery on the device is full. I get a alert message which says "Cannot Take Photo - There is not enough available storage to take a photo.You can manage your storage in Settings". I am given two options to click the "Done" button or "Settings" button. Clicking either of them does nothing and the app freezes completely.

This is what i get from the console logs

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

The code for the picker

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

I have implemented and tried all the delegates already and its not calling any delegate.

Is there any way i can implement something where i can use a listener to detect when this error occurs and take back the user to the previous screen ?

like image 620
user1861763 Avatar asked Jan 17 '13 17:01

user1861763


2 Answers

Sounds like your device run out of memory, system sent lots of "Out of Memory" notifications and your app got one, too. As result your app released the UIViewController, which originally launched UIImagePickerController.

Now when you dismiss imagePicker with Done/Settings button, control returns back to your app. The old UIViewController doesn't exist any more and you haven't implemented code to recreate it from scratch in this kind of situations. The device looks like it frozen, but only because UI wasn't redrawn by your app. Otherwise app works just fine.

You can check this case by implementing didReceiveMemoryWarning method into every UIViewController and logging, if it's called:

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

One of my favourite bugs. Easy to miss :)

like image 160
JOM Avatar answered Sep 25 '22 11:09

JOM


This sounds like a bug in iOS.

You should file a feedback at https://feedbackassistant.apple.com/.

like image 23
cocoahero Avatar answered Sep 22 '22 11:09

cocoahero