MFMailComposeViewController dismisses right away

2019-04-18 09:10发布

The situation is the MFMailComposeViewController was going to be presented. I saw it was presented half-way done, but then it got dismissed.

This is the error:

_serviceViewControllerReady:error: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)"

This is my source code to present the MFMailComposeViewController:

-(void) MailExecute {
    if ([MFMailComposeViewController canSendMail]) 
    {
        MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];   
        mailViewController.mailComposeDelegate = self;
        [mailViewController setSubject:NSLocalizedString(@"Check this new look", @"")];
        [mailViewController setMessageBody: @"my new look" isHTML:YES];

        [self presentModalViewController:mailViewController animated:YES];

        [mailViewController release];
    }
    else 
    {
        UIAlertView *alertInternal = [[UIAlertView alloc]
                                      initWithTitle: NSLocalizedString(@"Notification", @"")
                                      message: NSLocalizedString(@"You have not configured your e-mail client.", @"")
                                      delegate: nil
                                      cancelButtonTitle:NSLocalizedString(@"OK", @"")
                                      otherButtonTitles:nil];
        [alertInternal show];
        [alertInternal release];
    }
}

The weird point is that sometimes it happens, sometimes it doesn't. Please help me on this! I spend almost 1 working day to resolve this but no succeed.

9条回答
Anthone
2楼-- · 2019-04-18 09:45

I face the same problem and the solution was:

I delete the overall application appearence related code like

[[UILabel appearance]setText:@""] 

and replace with the code

[[UILabel appearanceWhenContainedIn:[self class], nil] setText:@""];

Now it is working fine so be carefull on overall application appearence changes: it might be navigationbar appearance, so and so

查看更多
▲ chillily
3楼-- · 2019-04-18 09:46

Your code looks correct, and as stated the error message strongly suggests this has something to do with UIView proper (not MFMail specifically). The problem almost surely lies somewhere elsewhere within your code, and might be challenging to troubleshoot.

Some things to look for:

  1. Other animations or view controller transitions/dismissals happening simultaneously or incorrectly (possibly like this)
  2. Release/retain issues, of course

If none of that seems like the fix, try commenting-out everything else happening in the view controller that calls this method and see if it works then.

If you still can't get it working, present the simplest version you can of failing code so we can troubleshoot further. :)

查看更多
霸刀☆藐视天下
4楼-- · 2019-04-18 09:51

I know this is the late reply, but may be help some other.

Just now face the same problem, By resetting the simulator work fine for me for this same issue. Let me know if this helps.

查看更多
登录 后发表回答