Meaning of Warning “while a presentation is in pro

2019-01-07 06:13发布

问题:

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 !!

回答1:

// 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.



回答2:

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



回答3:

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.



回答4:

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



回答5:

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.



回答6:

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.



回答7:

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.



回答8:

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];

    });