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
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With