【发布时间】:2019-05-09 06:39:54
【问题描述】:
我正在尝试保存从here 下载的大小为 7.9MB 的图像。但是在'try data.write ...'行,扩展程序崩溃了,我在控制台中得到了这个。
内核 EXC_RESOURCE -> 通知扩展[3137] 超出内存限制:ActiveHard 12 MB(致命)
内核 46710.034 内存状态:killing_specific_process pid 3137 [通知扩展](每个进程限制 3)-memorystatus_available_pages:73906
ReportCrash 启动延长事务计时器 默认 18:39:53.104640 +0530
ReportCrash 进程通知扩展 [3137] 被 jetsam 原因每个进程限制杀死
是不是因为 7.9MB 的大小太大而无法处理。如果是,那么它没有意义,因为在创建 UNNotificationAttachment 对象之前需要将媒体保存在临时存储中。在官方文档中,png 文件的限制为 10 MB,视频为 50 MB。我该如何解决?
let fileManager = FileManager.default
let folderName = ProcessInfo.processInfo.globallyUniqueString
guard let folderURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(folderName, isDirectory: true) else {
return nil
}
do {
try fileManager.createDirectory(at: folderURL, withIntermediateDirectories: true, attributes: nil)
let fileURL = folderURL.appendingPathComponent(fileIdentifier)
try data.write(to: fileURL, options: [])
let attachment = try UNNotificationAttachment(identifier: fileIdentifier, url: fileURL, options: options)
return attachment
} catch let error {
}
【问题讨论】:
-
看起来是内存问题而不是存储空间问题。
-
你的图片压缩了吗?如果您的数据是 jpeg 并且在过程中的某个位置被解压缩到 UIImage,它可能会超过 12MB
标签: ios swift ios-extensions unnotificationattachment unnotificationserviceextension