我在我的应用程序中遇到了一个奇怪的问题,我需要你的帮助!
我正在使用 MFMailComposeViewController 发送带有附件数据的电子邮件。附件是 PDF、CSV 或 XLS 文件。ZIP 文件也可以添加到邮件中。
在大多数情况下一切正常,但有时(实际上很常见),当附件是 XLS 并添加了 ZIP 时,我收到多个内存警告并且作曲家返回 MFMailComposeResultFailed,并出现一个根本没有帮助的错误(只说代码错误 1,“操作无法完成。(MFMailComposeErrorDomain 错误 1.)”)。
我的问题是它为什么这样做?我假设内存警告告诉我一些事情没有得到很好的管理,但我不知道是什么......
这是我发送电子邮件的代码
-(void) sendMail {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[self prepareMailPicker:picker];
NSString *filePath = [self getFilePath:pType];
NSString *zipFile = [self getZipPath];
NSString *mimeType;
int userPhoto = [User getCSVPhoto];
switch (pType) {
case EPDF:
mimeType = @"application/pdf";
userPhoto = [User getPDFPhoto];
break;
case ECSV:
mimeType = @"text/csv";
break;
case EExcel:
mimeType = @"application/vnd.ms-excel";
break;
default:
break;
}
NSData *attachmentData = [NSData dataWithContentsOfFile:filePath];
[picker addAttachmentData:attachmentData mimeType:mimeType fileName:[filePath lastPathComponent]];
if (userPhoto == 1 && shouldAddZip) {
NSData *zipData = [NSData dataWithContentsOfFile:zipFile];
[picker addAttachmentData:zipData mimeType:@"application/zip" fileName:[zipFile lastPathComponent]];
}
shouldAddZip = NO;
[self presentModalViewController:picker animated:YES];
}
-(void) prepareMailPicker:(MFMailComposeViewController*)picker {
picker.mailComposeDelegate = (id<MFMailComposeViewControllerDelegate>)self;
picker.navigationBar.tintColor = grayDark;
[picker setSubject:[TextManager textForKey:@"EMAIL_SUBJECT"]];
NSString *email = [[User currentUser] getEmail];
if (email && ![email isEqualToString:@""])
[picker setToRecipients:[NSArray arrayWithObject:email]];
NSString *emailBody = [TextManager textForKey:@"EMAIL_TEXT"];
[picker setMessageBody:emailBody isHTML:YES];
}
任何帮助将不胜感激!
编辑:正如@matt 所问,这里有一个日志来证明没有设置为 nil :
filePath : /var/mobile/Applications/A57F5CD2-E3FE-4417-8810-D746A22CF434/Documents/iNdF_Export_2012-11-19.xls
zipFile : /var/mobile/Applications/A57F5CD2-E3FE-4417-8810-D746A22CF434/Documents/iNdF_recus_2012-11-19.zip
attachmentData : (NSConcreteData *) <0x1d9c3c20> 53 874 bytes
zipData : (NSConcreteData *) <0x1f989100> 6 838 456 bytes