ios - MFMailComposeViewController 因附件过大而崩溃

标签 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)

最佳答案

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

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

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

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

关于ios - MFMailComposeViewController 因附件过大而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13677622/

相关文章:

iphone - 在Appdelegate类中控制一个类的AVAudioPlayer

ios - 为什么我的 UIView de 在删除观察者后第一次没有初始化,但之后却初始化了?

ios - 从 nib 加载 UICollectionViewCell 而不重用

ios - 当屏幕关闭时计时器应用程序可以工作

ios - 在 Swift 2、Xcode 7.0.1 中使用 'self'

ios - NSNumber 类型的托管属性?没有初始化为 nil

ios - 支持开发的 iOS 版本有哪些

javascript - 找不到 Sencha Touch 2 Logger.js

ios - NSMutableDictionary setobject : forkey: crashes with unrecognised selector message

ios - 使用 UICollectionView 放大选择的单元格