0

我正在使用 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)
4

2 回答 2

3

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

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

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

但除此之外,如果您的设备内存不足,则附件太大。如果设备在尝试附加电子邮件时内存不足,电子邮件服务很可能不会接受电子邮件,因为它会很大。

于 2012-12-03T05:33:01.683 回答
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];
于 2012-12-03T06:04:36.000 回答