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];
    }
}
Paul Peelen
  • 9,588
  • 15
  • 82
  • 162
  • 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. – Ants Jun 15 '13 at 00:00
  • 1
    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 http://stackoverflow.com/questions/13298448/ios6-mfmailcomposeviewcontroller-slow-to-load-and-flashes-black-screen-mailcom – Fattie Oct 31 '13 at 13:53
  • 1
    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. – Vadim Yelagin Nov 07 '13 at 04:08

3 Answers3

12

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.

Fattie
  • 30,632
  • 54
  • 336
  • 607
exu
  • 216
  • 3
  • 9
  • exu, this is a fantastic tip ------ and it seems to work 100% reliably. We did heaps of testing. Thank you so much, really. You really saved the day! – Fattie Oct 31 '13 at 13:53
  • 4
    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. – Fattie Oct 31 '13 at 14:18
  • 1
    Hey guys, what if I use UIActivityViewController?? – Stas Oct 13 '14 at 12:06
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

tt.Kilew
  • 5,614
  • 2
  • 30
  • 49
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]];
Paul Peelen
  • 9,588
  • 15
  • 82
  • 162
  • Ok, sounds reasonable. Do you formulate it dynamically? – Paul Peelen Mar 20 '13 at 23:26
  • 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]]; – MonkeyBusiness Mar 24 '13 at 13:19