3

After dismiss camera. It give me this warning: Attempt to present on while a presentation is in progress!

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

I don't know if this is a big issue.

More Code:

- (void) viewWillAppear:(BOOL)animated
{
    [self takePicture];
}


- (void) takePicture
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
    } else
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

    imagePickerController.delegate = self;
    [self presentViewController:imagePickerController animated:YES completion:nil];
}


- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

By the way, "dismissModalViewController" is deprecated.

Fix: ViewWillAppear will be invoked once there is a new view. That's the problem

Bill
  • 83
  • 1
  • 10
  • Please include more details in your question. – Ravi Oct 08 '13 at 18:14
  • The documentation tells you to use `dismissModalViewControllerAnimated:`, you were alt+click close to an answer. Read the documentation. – A-Live Oct 08 '13 at 18:19
  • @A-Live `dismissModalViewControllerAnimated:` is deprecated in favor of `dismissViewControllerAnimated:completion:`. He's using the correct one. – Kevin Oct 08 '13 at 19:58
  • @Kevin the method is deprecated but the documentation clearly tells to use it. The actual difference would be a good question. – A-Live Oct 09 '13 at 09:55
  • @A-Live What documentation are you looking at? The [UIViewController docs](https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIViewController/presentModalViewController:animated:) clearly state "Deprecated in iOS 6.0. Use dismissViewControllerAnimated:completion: instead." – Kevin Oct 09 '13 at 13:36
  • @Kevin Check documentation of `imagePickerControllerDidCancel:`. – A-Live Oct 09 '13 at 15:32
  • @A-Live just an old cross-reference that never got updated. – Kevin Oct 09 '13 at 15:42
  • @Kevin it would be the case if the new method didn't produce the warning from OP. In this case I see a strong reason to use a deprecated method until the issue is fixed by Apple. – A-Live Oct 09 '13 at 20:21
  • @A-Live I use the new methods to present and dismiss my ImagePickers, they're not the problem. The problem here is that somewhere along the line he's trying to present twice, dismiss twice, or dismiss while still presenting. – Kevin Oct 09 '13 at 21:01

2 Answers2

8

You should not present any controller from viewWillAppear because the presentation of the current view controller is not yet completed.

Call takePicture from viewDidAppear because viewDidAppear will be called once the presentation of controller completed .

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self takePicture];
}

Hope this will help you.

PKN
  • 146
  • 4
  • 2
    ViewDidAppear is the problem. Cuz every time I add a new view to view controller, that method is invoked. So I added a BOOL firstTimeRun to fix that. – Bill Oct 24 '13 at 14:15
  • **COMPLETE SOLUTION HERE**, John's answer: http://stackoverflow.com/questions/14453001/meaning-of-warning-while-a-presentation-is-in-progress – Fattie Jan 24 '14 at 07:44
0

You probably have presented some view controller like this

[self presentViewController:someVC animated:YES completion:nil];

and before the animation is get completed your below method is called

imagePickerControllerDidCancel

You can check it by changing it to

[self presentViewController:someVC animated:NO completion:nil];

notice animation:NO above.

msk
  • 8,885
  • 6
  • 41
  • 72
  • The only VC presented before is this UIImagePickerController. The warning shows after I click return in picker controller. @MSK – Bill Oct 08 '13 at 18:33
  • show us the code where you are presenting UIImagePickerController and some other code as well. – msk Oct 08 '13 at 18:41