I'm trying to dismiss a UIAlertView before showing another and I found the answer here: iOS dismiss UIAlertView beforing showing another
The problem is that this is not working on iOS7 but works on iOS6.
This is working in iOS6
-(void)closePreviousAlert{
for (UIWindow* w in [UIApplication sharedApplication].windows)
for (NSObject* o in w.subviews)
if ([o isKindOfClass:[UIAlertView class]])
[(UIAlertView*)o dismissWithClickedButtonIndex:[(UIAlertView*)o cancelButtonIndex] animated:YES];
}
Is there another solution for this?
Your code is not valid in iOS7 because [UIApplication sharedApplication].windows
doesn't have reference to UIAlertView
since the UIAlertView
itself is never added to any window in iOS7.
You need to keep reference to your actionSheet, this is best thing you can do.
You can do this with a reference to https://stackoverflow.com/a/19275311/1262634:
Class UIAlertManager = NSClassFromString(@"_UIAlertManager");
UIAlertView *alertView = [UIAlertManager performSelector:@selector(topMostAlert)];
Edit: this is a private API.
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