MFMailComposeViewController dismisses right away

淺唱寂寞╮ 提交于 2019-12-04 22:21:20
toblerpwn

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. :)

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.

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?

kttailor4u

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.

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.

Tr0yJ

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]];

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.

Use of modelViewController is deprecated in iOS 6 , use

[self presentViewController:mailView animated:YES completion:nil];
blunt knife

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!