sam
sam

Reputation: 461

How to dismiss alert view when application is put in background?

If I get an alert in my application and if I put application in background and press application icon to enter the application, a splash screen is displayed and then the alert pop up. Why splash screen appears? And if alert is not present and I put application in background and press application icon to enter the application, splash screen is not displayed.

Upvotes: 3

Views: 3564

Answers (5)

Dennis Stritzke
Dennis Stritzke

Reputation: 5558

If you want to dismiss all AlertViews programmatically you have to Remember a Reference to the currently shown Alterviews. I recommend a Singleton class where you ask for an AlertView and wich saves a Reference to the AlertView.

then you could use the

`- (void)applicationDidEnterBackground:(UIApplication *)application`

in your AppDelegate and call a Function on the Singleton Class, wich itself calls

[alert dismissWithClickedButtonIndex:0 animated:YES];

at all Alertviews.

Upvotes: 0

Thomas Nadin
Thomas Nadin

Reputation: 1207

The splash screen is as @akshay1188 mentions, is the Default.png in your project file. The reason for it being displayed, based on my best assumption, is because the OS has not managed to take a screenshot of your App before you go back to it. See this answer to a StackOverflow question where it was discussed.

As for the UIAlertView, @pKoul's anwser got my upvote.

Upvotes: 1

akshay1188
akshay1188

Reputation: 1667

The splash screen is actually the launch image that you might be using as Default.png

Upvotes: 0

Vincent Zgueb
Vincent Zgueb

Reputation: 1491

Maybe you can use the notification posted UIApplicationDidEnterBackgroundNotification in any class that needs some cleanup before entering bg. Do not forget to remove the observer in dealloc.

    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(cleanup:) 
                                                 name: UIApplicationDidEnterBackgroundNotification 
                                               object: nil]

Upvotes: 0

pmk
pmk

Reputation: 1897

First you have to make the UIAlertView a property in your class. In your AppDelegate Class you can implement the applicationDidEnterBackground: Method in wich you can put something like this:

[yourViewController.yourAlert dismissWithClickedButtonIndex:0 animated:NO];

This should dismiss the alert if your app enters the background. Hope this helps!

Upvotes: 6

Related Questions