MFMailComposeViewController因大附件而崩溃

时间:2012-12-03 05:23:34

标签: ios

我正在使用MFMailComposeViewController发送电子邮件 但是由于内存不足,它在发送大型附件时崩溃了 “邮件”是否为附件分配内存? 我应该怎么做

>
Dec  3 11:57:36 unknown kernel[0] <Debug>: launchd[1507] Builtin profile: container (sandbox)
Dec  3 11:57:36 unknown kernel[0] <Debug>: launchd[1507] Container: /private/var/mobile/Applications/776D8BB7-805E-46B1-B208-DF2CFE46AB3A [69] (sandbox)

> > 
Dec  3 11:57:48 unknown MobileMail[1483] <Warning>: Received memory warning.
Dec  3 11:57:49 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.mobilemail[0x26be]) Exited: Killed: 9
Dec  3 11:57:49 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.yourcompany.TestApp[0xc7ed]) Exited: Killed: 9
Dec  3 11:57:49 unknown UserEventAgent[12] <Notice>: jetsam: kernel termination snapshot being created
Dec  3 11:57:49 unknown SpringBoard[1186] <Warning>: Application 'TestApp' exited abnormally with signal 9: Killed: 9
>
Dec  3 11:57:50 unknown SpringBoard[1186] <Warning>: Application 'Mail' exited abnormally with signal 9: Killed: 9
Dec  3 11:57:50 unknown SpringBoard[1186] <Warning>: Received memory warning.
Dec  3 11:57:50 unknown ReportCrash[1509] <Error>: Saved crashreport to /Library/Logs/CrashReporter/LowMemory-2012-12-03-115750.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
Dec  3 11:57:50 unknown kernel[0] <Debug>: launchd[1510] Builtin profile: MobileMail (sandbox)

2 个答案:

答案 0 :(得分:2)

如果您的附件数据是磁盘上文件的内容,那么您可以做的最好,因为调用者是从映射文件创建NSData对象:

NSData * attachmentData = [NSData dataWithContentsOfFile:myPath 
      options:NSDataReadingMappedIfSafe error:&error];

这样可以将文件透明地保存在磁盘上,直到访问部分文件,并使系统尽可能高效。

但除此之外,如果设备上的内存不足,附件太大了。如果设备在尝试附加电子邮件时耗尽内存,那么电子邮件服务可能也不会接受电子邮件,无论如何它都会如此之大。

答案 1 :(得分:0)

邮件没有限制,但ISP会。大多数人的现实限制可能是10MB,但你可能希望将它保持在5MB左右,并在电子邮件中分割内容......

您可以使用以下代码

计算NSData的大小
NSData *pdfData=[NSData dataWithContentsOfFile:strpdfpath];

        NSLog(@"PDFData Length is %.02fmb",(float)(int)[pdfData length]/1048576);

然后您可以在成功附加后删除该文件,

[[NSFileManager defaultManager] removeItemAtPath:[strpdfpath stringByDeletingLastPathComponent] error:&err];