0

编辑:我最终联系了 Apple DTS。在我提供了受影响用户的堆栈截图后,DTS 决定我应该向 Apple BugReporter 提交错误。所以,在这一点上,我认为这是 MFMailComposer 的问题,但尚未解决。Apple 错误编号为 13602051

我有一个在应用程序中一次又一次出现的错误。

一些升级他们的 iOS 版本的用户报告他们不能再在我的应用程序中使用电子邮件导出,该应用程序使用 MFMailComposer。应用程序冻结,并且不生成崩溃报告。

我的代码非常简单,我无法重现报告的错误,但现在许多用户表示这会在 iOS 更新后发生。这是代码:

// using ARC, so no reference counting
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
@autoreleasepool {
  if (gpxFilePath) {
    NSData *gpx = [NSData dataWithContentsOfFile:gpxFilePath];
    [controller addAttachmentData:gpx mimeType:@"text/gpx" fileName:[self cleanFileName]];
    gpx = nil;
  }
}
[controller setSubject:subject];
[controller setMessageBody:body isHTML:YES];
[[MAP_APP_DELEGATE mainController] presentModalViewController:controller animated:YES];

调用此方法后,电子邮件视图出现,但随后无响应。

4

2 回答 2

0

This should solve your problem.

[[MAP_APP_DELEGATE mainController] presentModalViewController:controller animated:YES];

 controller = nil;
于 2013-06-07T18:43:08.280 回答
0

我正在使用 iOS 6.1 的下一个代码,它适用于我。

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc]init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"subject"];
    User *user = [user_array objectAtIndex:1];
    NSArray *toRecipients = [NSArray arrayWithObjects:@"mail address", nil];
    [mailer setToRecipients:toRecipients];
    NSArray *cc = [NSArray arrayWithObjects:@"mail address", nil];
    [mailer setCcRecipients:cc];
    NSDictionary *dic = [one array objectAtIndex:0];

    NSString *description = [dic objectForKey:@"Description"];

    NSString *emailBody = description;

    [mailer setMessageBody:emailBody isHTML:NO];
    [self presentViewController:mailer animated:YES completion:nil];
    [mailer release];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                    message:@"Your device doesn't support the composer sheet"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles: nil];
    [alert show];
    [alert release];
}

请记住,模拟器无法发送电子邮件,因此在这种情况下将显示警报视图。

注 1:presentModalViewController 在 iOS 6.0 中已弃用

注意 2:尝试发送没有数据的电子邮件以检查这是否是导致问题的原因

于 2013-03-08T08:06:02.763 回答