在 iOS 6 系统上启动 MFMailComposeViewController 实例时,我偶尔会看到以下错误。在 iOS 5 上一切正常,它只在 iOS 6 上发生:
* 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“* Collection [__NSArrayM: ...] 在枚举时发生了变异。”
错误发生在启动视图控制器的 viewWillDisappear() 函数被调用之后。
有没有其他人遇到过这个问题或遇到过修复?
谢谢!
代码很标准,但我还是把它包括在内:
-(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");}];
}