Trying to dismiss UIAlertController with unknown presenter Trying to dismiss UIAlertController with unknown presenter ios ios

Trying to dismiss UIAlertController with unknown presenter


I bet your crash occurred on iPad.

On iPad, from iOS8, UIActionSheet seem to be handled with a UIAlertController

With this code,

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {    if(buttonIndex == 1) return; // Cancel button    [self doSomeViewControllerDismisses];}

My app was crashing with the same error you got.
To prevent this, I just dispatch the complex dismiss call on the next MainThread execution, to give to the hidden UIAlertViewController the opportunity to release properly.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {    if(buttonIndex == 1) return; // Cancel button    dispatch_async(dispatch_get_main_queue(), ^{        [self doSomeViewControllerDismisses];    });}


A stack trace of this form generally indicates that you have navigated away from a UIViewController whilst an alert that you had it present is still dismissing.

The general remedy for that is to present or dismiss controllers in UIAlertViewDelegate's alertView:didDismissWithButtonIndex: method, since then you're sure that the presenter won't go away during any dismissal.

In your case, if you can't find any reproducible case you could try checking presentedViewController before presenting/dismissing a controller and see if that turns anything up.

But probably if you audit your controller transitions you'll find somewhere that responding to a system alert could programmatically trigger a navigation. Do you have any functionality that throws up a system alert for user authorization, like access to photos or whatever, and them denying it would result in a controller being programmatically dismissed by your error handling? That seems like a reasonably plausible scenario.


try to dismiss on main thread Alertview using Block on main thrad.

dispatch_async(dispatch_get_main_queue(), { () -> Void in  //  Write your alert view code in swift language .})