I have UIAlertController
. On click of OK, presenting MFMailComposeViewController
. I dismiss the MFMailComposeViewController
by tapping on cancel button in email compose screen. MFMailComposeViewController
's delegate methods are called properly while dismissing. MFMailComposeViewController
dismisses successfully. Immediately after that if I try the same feature(flow) again. I am not getting alert, rather getting below error. What could be the reason? I tried most of the solution available in stackoverflow. still getting the same issue.
Attempt to present <UIAlertController: 0x13890beb0> on <MFMailComposeViewController: 0x1371ef000> whose view is not in the window hierarchy!**
I am using self presentViewController
to present alertcontroller and MFMailComposeViewController
.
sample code is here :
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(nullable NSError *)error{
[controller dismissViewControllerAnimated:YES completion: nil];
}
UIAlertController * alertController= [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alertController dismissViewControllerAnimated:YES completion:nil];
MFMailComposeViewController *mailComposerVC = [MFMailComposeViewController new];
mailComposerVC.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[self presentViewController:(MFMailComposeViewController*)mailComposerVC animated: true completion: nil];
}
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:ok];
[alertController addAction:cancel];
[self presentViewController:alertController animated:false completion:nil];