0

I want to dismiss all alert view and action sheet like control if my apps moves to background so i put this code in objective c

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    Class AVClass = [UIAlertView class];
    Class ASClass = [UIActionSheet class];
    for (UIView * subview in subviews){
        NSLog(@"the class is %@",[subview class]);
        if ([subview isKindOfClass:AVClass]){
            [(UIAlertView *)subview dismissWithClickedButtonIndex:[(UIAlertView *)subview cancelButtonIndex] animated:NO];
        } else if ([subview isKindOfClass:ASClass]){
            [(UIActionSheet *)subview dismissWithClickedButtonIndex:[(UIActionSheet *)subview cancelButtonIndex] animated:NO];
        } else {
            [self checkViews:subview.subviews];
        }
    }
 }

but nothing happen i did not getting any alert view refrence in ios 8 Please suggest how to remove open Alert view .

Wain
  • 118,658
  • 15
  • 128
  • 151
user100
  • 327
  • 5
  • 19

1 Answers1

0

The code you have will never be reliable because it depends on Apple implementation details. Instead you should do something like send a notification each time you display an alert and have something (perhaps the app delegate, though that isn't ideal, better a class owned by the app delegate) observe those notifications and hold a weak reference to the alert view (set as the notification object).

Now, when the app goes to the background, you can iterate the list of weak references and dismiss each view. See this answer for implementation details.

Community
  • 1
  • 1
Wain
  • 118,658
  • 15
  • 128
  • 151