CloudKit。是否可以清除Caches\CloudKit\Assets?
CloudKit. Is it possible to clear Caches\CloudKit\Assets?
我将图像存储在 CKRecord 中作为 CKAsset。正因为如此,用了很多磁盘space。是否可以在从 CKAsset 获取图像后,在 App\Library\Cashes\CloudKit\Assets 处进行清理?
无法通过 CloudKit API 清理这些文件。
CloudKit 将为您管理 space,并且应该定期清理下载的资产,或者在出现低磁盘 space 通知时清理。您的应用程序无需担心。
我遇到了同样的问题,实际上我找到了解决方法:
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,然后将它们一一删除。
我将图像存储在 CKRecord 中作为 CKAsset。正因为如此,用了很多磁盘space。是否可以在从 CKAsset 获取图像后,在 App\Library\Cashes\CloudKit\Assets 处进行清理?
无法通过 CloudKit API 清理这些文件。
CloudKit 将为您管理 space,并且应该定期清理下载的资产,或者在出现低磁盘 space 通知时清理。您的应用程序无需担心。
我遇到了同样的问题,实际上我找到了解决方法:
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,然后将它们一一删除。