How to prevent merging multiple UIAlertView?

I am using MPMoviePlayerController on iOS. I listen to any errors that may occur when playing a video. In error handlers, I infer UIAlertView . Sometimes errors can occur in quick succession of each other, and thus many warning blocks are added up. For better user convenience, I do not want to pop up another warning if the previous one is shown.

+7
source share
6 answers

Try the following:

Set the boolean value true when a warning appears, set it to false when you close the warning, and always check the boolean value to see if it is true before you pop up. If this is true , you will know that you already have a warning window.

You can find this solution and another discussion here .

+5
source

You can implement this yourself trivially. Since you are displaying a warning, and you are also a delegate of the alert so you know when he left, you can easily track if there is a visible warning only by setting the Boolean flag for alerts and warnings. Thus, if a boolean value is set, you can cancel any subsequent warnings.

+1
source

When a warning appears, it will be moved to _UIAlertOverlayWindow. Therefore, a rather fragile method is to iterate over all windows and check if there are any UIAlertView routines.

 -(BOOL)checkAlertViewVisibleStatus { for (UIWindow* window in [UIApplication sharedApplication].windows) { NSArray* subviews = window.subviews; if ([subviews count] > 0) if ([[subviews objectAtIndex:0] isKindOfClass:[UIAlertView class]]) return YES; } return NO; } 

This is undocumented as it depends on the hierarchy of the internal view, although Apple cannot complain about it. A more reliable but even more undocumented method is to verify that `

[_ UIAlertManager visibleAlert]

`is zero.

These methods cannot check if the UIAlertView is displayed from SpringBoard.

+1
source

As far as I know, the only way is to keep track of whether a warning is currently displayed and / or someone is currently rejecting your application. Try to show the warning in appDelegate, and then use notification to notify appDelegate every time the warning is closed. This way appDelegate keeps track of whether there is a warning with a boolean flag variable.

0
source

Use the new UIAlertViewController. If you try to present a warning while the other is in sight, he ignores it and displays the warning shown below. This unpleasant side affects people who want the traditional behavior of folded warnings, but for your case this is a good solution.

 Warning: Attempt to present <UIAlertController: 0x7f9ef34c17e0> on <MasterViewController: 0x7f9ef344ec90> which is already presenting (null) 
0
source

It should work:

 -(BOOL) doesAlertViewExist { if ([[UIApplication sharedApplication].keyWindow isMemberOfClass:[UIWindow class]]) { return NO;//AlertView does not exist on current window } return YES;//AlertView exist on current window } 
0
source

All Articles