|
@@ -130,27 +130,16 @@ extension AppDelegate {
|
|
|
extension AppDelegate {
|
|
|
|
|
|
func handleKingfisher(){
|
|
|
-
|
|
|
-// let documentURL = FileManager.default.urls(
|
|
|
-// for: .documentDirectory,
|
|
|
-// in: .userDomainMask
|
|
|
-// ).first!
|
|
|
-//
|
|
|
-// let cache = try! ImageCache(
|
|
|
-// name: "permanent_image_cache",
|
|
|
-// cacheDirectoryURL: libraryURL
|
|
|
-// )
|
|
|
-
|
|
|
-
|
|
|
moveCacheSmoothly()
|
|
|
-
|
|
|
- let cache = ImageCache(
|
|
|
- name: "permanent_image_cache"
|
|
|
+// let cache = ImageCache( name: "permanent_image_cache")
|
|
|
+
|
|
|
+ let cache = try! ImageCache(
|
|
|
+ name: "permanent_image_cache",
|
|
|
+ cacheDirectoryURL: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask ).first!
|
|
|
)
|
|
|
cache.diskStorage.config.expiration = .never // 永不过期
|
|
|
cache.diskStorage.config.sizeLimit = 0 // 无大小限制
|
|
|
KingfisherManager.shared.cache = cache
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -161,12 +150,13 @@ extension AppDelegate {
|
|
|
dePrint("Cache Kingfisher 没有缓存,不用迁移")
|
|
|
return
|
|
|
}
|
|
|
- let srcURL = cachesURL.appendingPathComponent("com.onevcat.Kingfisher.ImageCache.permanent_image_cache")
|
|
|
+ let permanent_image_cache = "com.onevcat.Kingfisher.ImageCache.permanent_image_cache"
|
|
|
+ let srcURL = cachesURL.appendingPathComponent(permanent_image_cache)
|
|
|
guard fileManager.fileExists(atPath: srcURL.path) else { return }
|
|
|
|
|
|
//把srcURL 移动到新的 documentURL
|
|
|
guard let documentURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
|
|
|
- let dstURL = documentURL.appendingPathComponent("KingfisherCache")
|
|
|
+ let dstURL = documentURL.appendingPathComponent(permanent_image_cache)
|
|
|
|
|
|
// 4. 处理目标已存在的情况
|
|
|
if fileManager.fileExists(atPath: dstURL.path) {
|
|
@@ -179,22 +169,15 @@ extension AppDelegate {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- do {
|
|
|
- try fileManager.createDirectory(at: dstURL, withIntermediateDirectories: true, attributes: nil)
|
|
|
- } catch {
|
|
|
- dePrint("创建目录失败: \(error.localizedDescription)")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
do {
|
|
|
dePrint("srcURL=\(srcURL)")
|
|
|
dePrint("dstURL=\(dstURL)")
|
|
|
-// try fileManager.copyItem(at: srcURL, to: dstURL)
|
|
|
try fileManager.moveItem(at: srcURL, to: dstURL)// 移动文件
|
|
|
} catch {
|
|
|
debugPrint("尝试移动文件失败: \(error.localizedDescription)")
|
|
|
}
|
|
|
+
|
|
|
|
|
|
dePrint("移动 Cache Kingfisher 到 library 流程结束")
|
|
|
}
|