iOS临时目录中的文件大小限制是多少? [英] What is the file size limit in temporary directory in iOS?

查看:287
本文介绍了iOS临时目录中的文件大小限制是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存从

I am trying to save an image of size 7.9MB downloaded from here. But at line 'try data.write...' the extension crashes and I get this in console.

内核EXC_RESOURCE->通知扩展[3137]超出内存限制:ActiveHard 12 MB(致命)

kernel EXC_RESOURCE -> Notification Extension[3137] exceeded mem limit: ActiveHard 12 MB (fatal)

内核46710.034 memorystatus:killing_specific_process pid 3137 [Notification Extension](每个进程限制3)-memorystatus_available_pages:73906

kernel 46710.034 memorystatus: killing_specific_process pid 3137 [Notification Extension] (per-process-limit 3) - memorystatus_available_pages: 73906

ReportCrash启动延长事务计时器 默认18:39:53.104640 +0530

ReportCrash starting prolongation transaction timer default 18:39:53.104640 +0530

Reportsrash流程通知扩展[3137]被jetsam原因per-process-limit杀死

ReportCrash Process Notification Extension [3137] killed by jetsam reason per-process-limit

是因为7.9MB的大小对于它来说太容易处理了.如果是这样,则没有意义,因为必须在创建UNNotificationAttachment对象之前将媒体保存在临时存储中.在官方文档中,png文件的限制为10 MB,视频文件的限制为50 MB.我该如何解决?

Is it because 7.9MB size is too much for it too handle. If it is then it doesn't make sense as it is necessary to save media in temporary storage before creating an UNNotificationAttachment object. In official documentation the limit for png files is given as 10 MB and for videos it is 50 MB. How do I solve this?

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 {

}

推荐答案

我不知道您可以写入临时目录的内容(可用空间除外)是否有大小限制 ),但我可以告诉您,我已经编写了一些客户端应用程序,该应用程序将数百兆字节写入该目录.那不是你的问题.

I don't know if there is a size limit on the contents you can write to the temporary directory (other than free space) but I can tell you that I've written client apps that write hundreds of megabytes to that directory. That's not your problem.

这篇关于iOS临时目录中的文件大小限制是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆