I receive this exceptional only occasionally (about 20% of the times) when my controller attempts to present the modal UIImagePickerController
. I have researched this topic quite a bit on SO, and have followed the instructions of similar questions on this topic about putting various safeguards. While this was able to reduce the frequency that I have gotten this error, I still receive it and am unsure what I could do to prevent it from happening.
My set up is the following: my root controller is a Tab Bar controller, in which I then have embedded a navigation controller. Inside this navigation controller I have TakePhoto1Controller
, and I present my ImagePickerController
modally when someone wants to take a picture.
My code is as the following:
BOOL modalPresent = (BOOL)(self.presentedViewController);
//Present the Camera UIImagePicker if no image is taken
if (!appDelegate.imageStorageDictionary[@"picture1"]){
if (modalPresent == NO){ //checks if the UIImagePickerController is already modally active
if (![[self imagePickerController] isBeingDismissed]) [self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:self.imagePickerController animated:NO completion:nil];
}
}
The error I am getting is the following:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .'"