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条回答
闹够了就滚
2楼-- · 2019-04-18 09:36

MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc]init];

if ([MFMailComposeViewController canSendMail])
{
    mailComposer.mailComposeDelegate = self;
    [mailComposer setToRecipients:[NSArray arrayWithObject:@"support@kapsie.com"] ];
    [mailComposer setSubject:@"Kapsie App Contact Support"];
    [mailComposer setMessageBody:@"Type Your Feedback message here" isHTML:NO];
    [self presentViewController:mailComposer animated:YES completion:nil];
}

Use above code and check it on device.

查看更多
放荡不羁爱自由
3楼-- · 2019-04-18 09:41

The issue for me was an incorrect argument when calling the attachment function. If you are having this issue with an email attachment I suggest following the solution found in this thread, as follows:

NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:[path lastPathComponent]];
查看更多
不美不萌又怎样
4楼-- · 2019-04-18 09:41

Use of modelViewController is deprecated in iOS 6 , use

[self presentViewController:mailView animated:YES completion:nil];
查看更多
爷的心禁止访问
5楼-- · 2019-04-18 09:43

This problem can occur when displaying a remote view controller -- a view controller run in another process -- as indicated by the UIViewService reference in the error message.

I've had this problem when displaying an SKStoreProductViewController, which is also a remote view controller. I'm not sure what the root cause is; the only thing that seemed to trigger it for me was presenting the view controller repeatedly.

For the SKStoreProductViewController I was able to check for this error in the completion block of the loadProductWithParameters:completionBlock: method. Does the MFMailComposeViewControllerDelegate give you a callback with an error about this? It may be that all you can do is listen for this error and show an error message to the user.

We should both probably file an apple radar about this.

查看更多
萌系小妹纸
6楼-- · 2019-04-18 09:43

After I stored the MFMailComposeViewController in a strong property of my class instead of a local variable I could not reproduce the self-dismissing behaviour any more.

查看更多
闹够了就滚
7楼-- · 2019-04-18 09:44

Do you have anything in your viewDidDisappear: or viewWillDisappear methods that would dismiss a view controller?

If not, can you post more of your code for the ViewController that presents the MFMailComposeViewController?

查看更多
登录 后发表回答