Issue when using MFMailComposeViewController
Asked Answered
T

3

27

I have a tricky problem. In one of my app, with over 150.000 downloads... I have a problem which seldom occurs and which I can't seem to figure out.

The problem is the following: In a view where the user can share a list via email, I open the mail window using MFMailComposeViewController. However, in some few cases the app seems to get a problem using the mail composer. The user presses the share button, the mail windows slides up, waits about 1-2 sec and then closes again. No content in the mail window, although I do send data to it. I myself have not been able to re-create the problem on any device or in the simulator, however one colleague has. I ran the app using XCode on his phone and got the following in the logs:

2013-03-01 14:43:39.604 appname[318:907] <MFMailComposeRemoteViewController: 0x1ebfb100> timed out waiting for fence barrier from com.apple.MailCompositionService
2013-03-01 14:43:39.631 appname[318:907] viewServiceDidTerminateWithError: Error Domain=XPCObjectsErrorDomain Code=2 "The operation couldn’t be completed. (XPCObjectsErrorDomain error 2.)"

I googled the error "timed out waiting for fence barrier from com.apple.MailCompositionService" but can't really find any help.

Does anybody have any experience with this? How can I solve it?

My code for opening the view:

-(void)displayComposerSheetWithBodyString:(NSString *)aBody
{
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
        picker.mailComposeDelegate = self;

        [picker setSubject:@"Lista"];

        NSString *emailBody = aBody;
        [picker setMessageBody:emailBody isHTML:NO];

        [self.navigationController presentModalViewController:picker animated:YES];
    }
    else
    {
        [[[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Din enhet är inte redo att skicka e-post. Kontrollera dina inställningar", nil)
                                   message:nil
                                  delegate:self
                         cancelButtonTitle:NSLocalizedString(@"OK", nil)
                         otherButtonTitles:nil]
         show];
    }
}
Trioxide answered 1/3, 2013 at 13:54 Comment(3)
Hey, I'm experiencing the exact same problem you describe. A friend has this problem on an iPhone 4 but I cannot reproduce it on a iPod touch 4th gen, 3GS, 4S or a 5. I thought maybe it was due to the size of the attachment so also tried zipping it (was a csv), but no difference.Abysmal
Experiencing exactly the same problem, November 2013. Thank goodness, the workaround works use one global MFMailComposeViewController and only use that .. then you are golden. Identical question here #13298948Prone
I'm experiencing the exact same problem. On iOS 6 the composer opens and then closes, on iOS 7 it works but is unresponsive for a couple of seconds. Looks like synchronisation bug by Apple. When presenting MFMailComposeViewController in dispatch_after block (with minimal delay, say, 0.1 sec) it does not fail and is ready for user interaction almost instantly.Barbuto
S
13

Not sure if you have fixed the problem, but I have met it recently in my project.

A workaround I did was to allocate and initiate MFMailComposeViewController in an earlier stage, and hold it in one static variable, whenever it's needed, get the static MFMailComposeViewController instance and present it.

It seems working for me, hope it will work for you, too.

Sitter answered 18/6, 2013 at 8:0 Comment(2)
Furthermore, you will almost certainly have to "cycle" the global MFMailComposeViewController after each use. It is not reliable to "re-use" the same one. Have a global routine which release and then re-initializes the singleton MFMailComposeViewController. Call it each time after you are finished with it. What a hassle.Prone
Hey guys, what if I use UIActivityViewController??Maniacal
E
5

a had the same issue, and this fixe helped me:

https://twitter.com/christian_beer/statuses/321295533077565440

"@nathangaskin well… that was long ago :) But if I remember correctly, it worked after I removed the custom fonts from my UIAppearance code"

It works fine for me.

Also, second option is to simply wrap displaying call into

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

block

Excurrent answered 11/11, 2013 at 15:46 Comment(1)
I like that solution better than allocating the view controller statically & earlier.Nosography
P
4

I have exactly the same issue. I think I have nailed it down to the time it takes to formulate the message body string.

Content from comment

 //Message Body 
NSString *msgBody = [NSString stringWithFormat:
                        @"I noticed these results in pocketKPI. The %@ was at %@ which is a variance of %@(or %@) to the target defined as %@. When you have some time let's discuss.", 
                        self.itemToView.kpiName, 
                        [DFSKpiFormatter formatNumberAsString:self.itemToView.currentValue], [self.itemToView determineVarianceLabelText],
                        [self.itemToView determineVariancePercentLabelText], 
                        [DFSKpiFormatter formatNumberAsString:self.itemToView.targetValue]];
Purple answered 20/3, 2013 at 22:20 Comment(2)
Ok, sounds reasonable. Do you formulate it dynamically?Trioxide
Yes I do. //Message Body NSString *msgBody = [NSString stringWithFormat:@"I noticed these results in pocketKPI. The %@ was at %@ which is a variance of %@(or %@) to the target defined as %@. When you have some time let's discuss.", self.itemToView.kpiName, [DFSKpiFormatter formatNumberAsString:self.itemToView.currentValue], [self.itemToView determineVarianceLabelText],[self.itemToView determineVariancePercentLabelText], [DFSKpiFormatter formatNumberAsString:self.itemToView.targetValue]];Purple

© 2022 - 2024 — McMap. All rights reserved.