0

In my app I give a alert, if the user wants to confirm the offer or not. Now I noticed that if the user hits the home button, the alert stays there & makes my app crash if he would enter anything. How can I remove the alert (all UIAlerts) when I go to background mode?

Kind regards,

Glenn.

Edit 1:

Basically I a making a offer page. When the user clicks OK, I am showing a UIAlert for extra confirmation. Now I also have functionality that when a user closes (home button) the app & restarts it, it will go to the overview page (where all the products are) and will ask the server for the data (makes the data up -to-date again.).

Normally there would be no problem with my app going into background mode. But with the functionality of refreshing the data & going to another controller it probaly gives problems. Therefore I need to be able to close all the UIAlerts still active.

Glenn Bettens
  • 65
  • 1
  • 8
  • from the "offer page”... dismiss the alert view [theAlertView dismissWithClickedButtonIndex:0 animated:YES]; .. when your app goes to background – TonyMkenu Sep 07 '14 at 20:54
  • & how can I check when my app goes to the background? is there a special commando to do this? – Glenn Bettens Sep 08 '14 at 05:59
  • There's a notification UIApplicationWillResignActiveNotification that fires when the home button is pressed; http://stackoverflow.com/a/9012734/1702413 – TonyMkenu Sep 08 '14 at 07:12
  • You can try, also... In ViewDidDisappear or viewWillDisappear to dismiss the alert – TonyMkenu Sep 08 '14 at 07:55
  • Ok so what i'm doing now. I made a static UIAlertView that I dismisWithClickedButton when I my app goes in Background (in the AppDelegate.cs) so tanks for clarifying that! ;) – Glenn Bettens Sep 08 '14 at 10:57

2 Answers2

0

You app crashes not because of UIAlerts but because something is going wrong. Even if you put an app in the background while showing a UIAlert, the alert stays there.

Nikos M.
  • 13,685
  • 4
  • 47
  • 61
  • Yeah well the problem is that, if I go back to my app, I show another controller (and refresh the data there). So the alert ain't gonne work anymore ==> Makes my app crash. – Glenn Bettens Sep 05 '14 at 09:29
0
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

you can use it with this method in AppDelegate.m:

- (void)applicationDidEnterBackground:(UIApplication *)application

but Nikos M. was right: you should find and fix the source of this problem, but not to disguise it. there is a simplest way to show alert, check it, may be it'll help:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Some message" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
Community
  • 1
  • 1
aquarium_moose
  • 355
  • 1
  • 11