Question

When my iOS app launches for the first time, I automatically open a "welcome" modal like this:

UIViewController *intro = [self.storyboard instantiateViewControllerWithIdentifier:@"intro"];

intro.modalPresentationStyle = UIModalPresentationFullScreen;

//Show the modal
[self presentViewController:intro animated:NO completion:nil];

Inside that modal, the user is instructed to link the app to Dropbox. They tap a button that fires this:

[[DBSession sharedSession] linkFromController:self];

This is a Dropbox SDK method that opens a Dropbox authentication UIWebView in another modal that looks like this: http://d.pr/i/6ZnC

Once they sign in, the modal automatically animates closed.

I then try to close the original intro modal with this:

[self dismissViewControllerAnimated:YES completion:nil];

But I get this warning and the modal does not close:

Warning: Attempt to dismiss from view controller <PPIntroViewController: 0xf296ab0> while a presentation or dismiss is in progress!

Here's what I've tried:

  1. I put an artificial delay right before dismissViewControllerAnimated to let the Dropbox modal close, but it doesn't help: [NSThread sleepForTimeInterval:2.0];
  2. I've tried turning off the animation: [self dismissViewControllerAnimated:NO completion:nil]; and that doesn't help either.
  3. I've tried checking for the modal dismissal already in progress: if(![self isBeingDismissed]){ ... } and no luck.

Any ideas? How can I determine what exactly is presenting/dismissing and preventing the modal from closing?

iOS 7 + Xcode 5

Was it helpful?

Solution

I found that issue. You can see this line in DBSession+ios.m

[rootController presentModalViewController:navController animated:YES];

So, internally they will present their authentication view controller from self. Already you've present your view controller from self. So when either they or you try to dismiss view controller from self, give this warning because it had presenting view controller. So instead of pass self to dropBox, pass intro view controller.

[[DBSession sharedSession] linkFromController:intro];

OTHER TIPS

Try calling the

[self dismissViewControllerAnimated:YES completion:nil];

From inside the introViewController rather than from in the root one. This should call on self.presentingViewController if there is no other modal. So I'd nest one in the completion handle block of the first

I Found that this issue occurs if you trying to push/dismiss view controller while previous transaction (animation) in progress.

Take NSTimer and dismissViewController between 0.50 to 1 second. This is helpful trick so your current viewController has done its animation.

Otherwise not sure but try to set NO with dismissViewControllerAnimated.

[self dismissViewControllerAnimated:NO completion:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top