我在CKRecord中将图像存储为CKAsset。因此,占用了大量的磁盘空间。从CKAsset获取图像后,是否可以在App\Library\Cashes\CloudKit\Asset中进行清理?
发布于 2015-03-30 22:05:53
不可能通过CloudKit API清理这些文件。
CloudKit将为您管理该空间,并且应该定期清理下载的资产,或者在磁盘空间较低的情况下进行通知。您的应用程序不需要担心它。
发布于 2016-04-21 07:14:07
我也有同样的问题,实际上我在周围找到了一份工作:
let fileManager = NSFileManager.defaultManager()
let cachePath = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true) as [String]
let filePath = "\(cachePath[0])/CloudKit/Assets"
do {
let contents = try fileManager.contentsOfDirectoryAtPath(filePath)
for file in contents {
try fileManager.removeItemAtPath("\(filePath)/\(file)")
print("Deleted: \(filePath)/\(file)") //Optional
}
} catch {
print("Errors!")
}本质上,我手动导航到CloudKit/Asset文件夹,并检索存储在其中的所有CKAssets,然后逐个删除它们。
发布于 2022-09-23 10:59:37
谢谢!这个很管用。尽管缓存目录现在位于具有UID的目录中。
我尝试删除整个cloudkit目录,这似乎没有副作用。iOS立即重建了它,但将我的应用程序的有效负载从20Gb+减少到了700 my。
虽然iOS会处理这个问题,而且表面上没有理由手动执行,但我的数据容器的巨大大小使得无法在本地下载来进行测试。
更新快速5.x代码
let fileManager = FileManager.default
let cachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true) as [String]
let filePath = "\(cachePath[0])/CloudKit"
do {
let contents = try fileManager.contentsOfDirectory(atPath: filePath)
for file in contents {
try fileManager.removeItem(atPath: "\(filePath)/\(file)")
print("Deleted: \(filePath)/\(file)") //Optional
}
} catch {
print("Errors!")
}https://stackoverflow.com/questions/29341117
复制相似问题