How to get alert when when level=2 warning occurs in didReceiveMemoryWarning method in iPhone [duplicate]
Possible Duplicate:
Generating alert to User when didReceiveMemoryWarning is called
In my application i will take images with camera and set that as background image. some times i am getting Warning as "Warning Received Level=1.". After paying with this fo开发者_如何转开发r some times, i got another Warning as "Warning Received Level=2." At these times "didReceiveMemoryWarning " method will be called. If I get level=2 Warning I want to display an alert to the User. How Can I do that Programatically.
Can Anyone Please Help me. Thanks in Advance.
You should not display an alert to the user - it is not the user's concern that you get memory warning. You should rather try and find out why you use so much memory and possibly leaks you might have. Moreover, on memory alerts, you should get rid of things you don't require at that moment (and you can easily recreate when needed).
As Paul pointed out, you shouldn't do this in your final app. Displaying alerts that are anything short of critical depletes the "magic" that comes with the iPhone.
Assuming you are just doing this for yourself and testing purposes, you can so with an UIAlertView
like so:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Memory Warning"
message: @"Level 2 Memory Warning has been born. Fix me, will ya?"
delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
There's no way to distinguish between a level 1 and a level 2 warning. So even if you know how to display an alert, you can't limit it to level 2 warnings.
精彩评论