50

When I am integarting the Instagram in my project. I am getting a image from UIImagePickerController and after it i want to send it to Instagram But when I am sending image to Instagram by UIDocumentInteractionController delegate method presentOptionsMenuFromRect:inView: animated: like this

[documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];

The warning comes Warning: Attempt to present <_UIDocumentActivityViewController: 0x7584780> on while a presentation is in progress!
The application is not Crashing. But I am not getting the Problem. Why this warning comes and what It means. I searched on Internet and read questions about this but not got any answer. Help me !!

TheTiger
  • 13,264
  • 3
  • 57
  • 82
chakshu
  • 1,372
  • 2
  • 10
  • 21
  • 1
    In short: you are opening the next view **DURING THE CLOSING ANIMATION OF THE PREVIOUS ONE**. This infuriating problem, is that simple. Simply uses John's code below to absolutely ensure the closing-animation has finished before the next one begins. – Fattie Jan 24 '14 at 07:35

8 Answers8

148
// Breaks
[viewController1 dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:viewController2 animated:YES completion:NULL];

// Does not break
[viewController1 dismissViewControllerAnimated:YES completion:^{
    [self presentViewController:viewController2 animated:YES completion:NULL];
}];

The Swift 3 version of the above code would look like this:

// Breaks
viewController1.dismiss(animated: true)
present(viewController2, animated: true)

// Does not break
viewController1.dismiss(animated: true) {
    present(viewController2, animated: true)
}

Note the use of the completion handler in the second example above.
It only presents viewController2 after viewController1 has been fully dismissed.

zx485
  • 28,498
  • 28
  • 50
  • 59
John Erck
  • 9,478
  • 8
  • 61
  • 71
7

For those needing/wanting the swift 3 version, here it is

viewController1.dismiss(animated: true, completion: {
    self.present(self.viewController1, animated: true)
})

viewController1 is the viewcontroller you want to present.

Micah Montoya
  • 757
  • 1
  • 8
  • 24
3

It means you are presenting or dismissing UIImagePickerController and trying to present UIDocumentInteractionController, while first presentation or dismissing is not completed.

Timur Mustafaev
  • 4,869
  • 9
  • 63
  • 109
  • can you tell me the proper solution of this problem.i can only call present UIDocumentInteractionController in the UIImagepicker's delegate method didFinishPickingImage – chakshu Jan 23 '13 at 09:18
  • Yes, you should present it in didFinishPickingImage method. After UIImagePicker will be dismissed – Timur Mustafaev Jan 23 '13 at 09:26
2

This means that you are presenting 2 ViewControllers at the same time. Call your delegate after the first presentation is completed.

2

This can also occur if you've got (say) a UIButton hooked up to an IBAction to present a ViewController, and also create a segue in the Storyboard from the button to the target ViewController.

Had this happen when I forgot to delete the IBAction connection from a UIButton when I shifted some interactions around.

Deleting either the IBAction connection or the segue will resolve it.

axol
  • 75
  • 6
2

i got this message because i copied pasted a button that already had sent event attached to it and i continued to create another connection since new button was supposed to open new view.

So technically i was trying to open 2 views at the same time.

user2251695
  • 129
  • 10
2

Try..

    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

        [self performSegueWithIdentifier:@"Identifier" sender:self];

    });
ArNo
  • 2,278
  • 1
  • 22
  • 19
1

As it was said before, this means that you are trying to present 2 modal windows or popovers at the same time. But in my case I haven't seen any modal window or popover when I getting this message.

The reason for the error in my case was following. When I called the popover to show up for the very first time, it was another error which prevent popover to show but it somehow continue to be in "presented" state. All following attempts to show popover failed with runtime error "while a presentation is in progress!”.

So, if you run into the same situation, look through the log and try find very first error starting with *** WebKit discarded an uncaught exception in the....

Hope it will save somebody's time.

Mike Keskinov
  • 11,614
  • 6
  • 59
  • 87