-2

I have referred the following links for this issue, but neither of the solutions worked for me:

Link 1

Link 2

I think these solutions don't work for iOS7.

So now how would I be able to find out whether there is any UIAlertView open, when my application enters in background state. I want to dismiss the UIAlertView before going into the background.

Community
  • 1
  • 1
Kanan Vora
  • 2,124
  • 1
  • 16
  • 26

3 Answers3

1

You get a notification when the app is send to background, so detect that notification in the class that displays the alert view and remove it, that's all

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • Can u elaborate a bit, how to detect notification for background in particular class – Kanan Vora Dec 05 '13 at 12:10
  • 2
    @KananVora You can register for UIApplicationDidEnterBackgroundNotification in the particular viewController you want to receive the notification. – dispatchMain Dec 05 '13 at 12:23
1

have you checked UIAlertView property @property(nonatomic, readonly, getter=isVisible) BOOL visible Also while going in the background you get a notification in - (void )applicationDidEnterBackground: you can check there and remove all alertviews if any

Dinesh
  • 929
  • 7
  • 25
1

Remove alert in applicationDidEnterBackground

Add this line in your class

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

And implement method as well

- (void)enteredBackground:(UIApplication *)application
    {
        if (mainAlertView && mainAlertView.isVisible) 
                 [mainAlertView dismissWithClickedButtonIndex:0 animated:NO];
    }
Bhumeshwer katre
  • 4,671
  • 2
  • 19
  • 29