2

I am sporadically seeing the following error when I launch an instance of MFMailComposeViewController on iOS 6 systems. Everything functions fine on iOS 5, it only happens on iOS 6:

* Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection [__NSArrayM: ...] was mutated while being enumerated.'

The error occurs just after the launching view controller's viewWillDisappear() function is called.

Has anyone else run into this problem or come across a fix for it?

Thanks!

The code is pretty standard, but I've included 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");}];
}
Chrissy Harris
  • 251
  • 2
  • 7
  • I'm experiencing the same problem. Chrissy, did you find a solution or may be a workaround? – Alexey Golikov Jan 08 '13 at 12:27
  • 1
    Hi Alexy-- I did find a solution, but it's 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, the errors sporadically occur. It makes absolutely no sense to me, but when we stopped calling setBackgroundImage() on the UIBarButtonItems, the sporadic array mutation errors stopped happening. Go figure... – Chrissy Harris Jan 11 '13 at 21:30

0 Answers0