iOS6: MFMailComposeViewController slow to load and flashes black screen; MailCompositionS begins hogging memory
Asked Answered
M

2

16

On iOS 6, after sending a few email messages (by using MFMailComposeViewController), the email screens become very slow to open- at first opening with none of the fields populated (no Subject, no body, etc.) for a few seconds, and eventually (after sending about 8 messages), a black screen is displayed to the user for a few seconds before the email view controller is properly displayed.

The log spits out the following line before each black screen is displayed:

[MFMailComposeRemoteViewController: ....] timed out waiting for fence barrier from com.apple.MailCompositionService

Also, using MFMailComposeViewController on iOS6 causes the MailCompositionS process to start hogging memory (it's going all the way up to roughly 260MB on my iPhone). I'm assuming this is the reason for the MFMailComposeViewController display issues.

Everything runs fine on iOS 5. This issue only occurs on iOS 6.

Has anyone found a way to resolve this issue?

Thanks!

The code is standard, but I'll include it anyway:

-(IBAction)doEmailLog:(id)sender 
{    
    if( [self canSendMail] )
    {       
        // create the compose message view controller
        MFMailComposeViewController* mailComposer = [[MFMailComposeViewController alloc] init];

        // this class will handle the cancel / send results
        mailComposer.mailComposeDelegate = self;

        // fill in the header and body
        [mailComposer setSubject:@"My Subject"];
        [mailComposer setMessageBody:@"My message body" isHTML:NO];

        // attach log file
        if ([[NSFileManager defaultManager] fileExistsAtPath:filename])
        { 
            NSData *data = [NSData dataWithContentsOfFile:filename];
            [mailComposer addAttachmentData:data mimeType:@"text/plain" fileName:filename];
        }

        // show the view controller
        [self presentViewController:mailComposer animated:YES completion:^{LogTrace(@"Presented mail view controller");}];
    }
    else
    {
        ...
    }
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    ...

    // dismiss the compose message view controller
    [self dismissViewControllerAnimated:YES completion:^{LogTrace(@"Finished dismissing mail controller");}];
}
Mantel answered 8/11, 2012 at 21:52 Comment(1)
It's November 2013 .. the workaround seems to be use a global MFMailComposeViewController .. don't use a local one. Weird! Identical question here ... #15159912 .. "exu" first proposed the solution, thank you exu!Swithbert
B
3

on ios 6 the mail composer is its own app (inside yours) :: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/


the code looks good to me if you are using ARC else it leaks and on ios6 that might result in x XPC remotes

if all is good there, Id blame it on a bug in apple's new handling of XPC

Berg answered 8/11, 2012 at 22:5 Comment(5)
Thanks for the response! Yep-- I'm using ARC, so no leaking should be going on in those snippets. I saw Ole's blog, and while it's very informative, it offers no solution. Still looking for a solution...Mantel
The cause of this issue is very odd... The view controller that launched MFMailComposeViewController has a navigation bar. If you change the background image of the buttons on the navigation bar in the launching view controller's viewWillAppear() and viewWillDisappear() functions, MailCompositionServiceS will use and hang onto 7-10MB of memory each time you launch and dismiss MFMailComposeViewController. It makes absolutely no sense to me, but when we stopped calling setBackgroundImage() on the UIBarButtonItems, the memory issue in MailCompositionServiceS stopped happening. Go figure...Mantel
Have you found solution for this problem ?Gossett
Yep. Had the same problem. I quit the simulator and restarted it; problem solved(!?)Unremitting
What a miserable problem. We have a lot of test equipment so "fortunately" found the problem. The workaround of using only a global composer seems top be completely solid. Hope it helps someone.Swithbert
R
0

there's another possible solution:

Remove custom fonts from the appearance methods, if you have any

https://mcmap.net/q/511468/-issue-when-using-mfmailcomposeviewcontroller

Redfish answered 11/11, 2013 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.