Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to dismiss all the alertviews opened in iOS7

I am new to iOS.I am developing an application which contain notifications.While using the app when a notification arrives an alertView is displayed.Everything works fine but if notification arrives when another alertView is already displayed problem starts.Notification alertView is displayed above the existing alertView.When I click OK for the notification alertView UI navigates to a new view controller and there the fist alertView remains displayed.If i click on that alertView my app crashes.

Is there any way to close all the alertviews that is displayed, when I click on the notification alertView.

I got this solution

for (UIWindow* window in [UIApplication sharedApplication].windows) 
{
  NSArray* subviews = window.subviews;
  if ([subviews count] > 0)
    if ([[subviews objec`enter code here`tAtIndex:0] isKindOfClass:[UIAlertView class]])
      [(UIAlertView *)[subviews objectAtIndex:0] dismissWithClickedButtonIndex:[(UIAlertView *)[subviews objectAtIndex:0] cancelButtonIndex] animated:NO];
}

But this code works for iOS6 not iOS7. I want a corresponding code in iOS7.

Can anyone please help.Thanks in advance

like image 553
Joe Mathews Avatar asked Sep 05 '14 11:09

Joe Mathews


1 Answers

 UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; 
        [alert1 show];
        [self performSelector:@selector(dismiss:) withObject:alert1 afterDelay:1.0];

-(void)dismiss:(UIAlertView*)alert
{
    [alert dismissWithClickedButtonIndex:0 animated:YES];
}
like image 138
bhavik Avatar answered Nov 06 '22 03:11

bhavik