|
|
@@ -178,25 +178,32 @@ open class ImageCache {
|
|
|
self.diskStorage = diskStorage
|
|
|
let ioQueueName = "com.onevcat.Kingfisher.ImageCache.ioQueue.\(UUID().uuidString)"
|
|
|
ioQueue = DispatchQueue(label: ioQueueName)
|
|
|
-
|
|
|
+
|
|
|
+ let notifications: [(Notification.Name, Selector)]
|
|
|
#if !os(macOS) && !os(watchOS)
|
|
|
#if swift(>=4.2)
|
|
|
- let notifications: [(Notification.Name, Selector)] = [
|
|
|
+ notifications = [
|
|
|
(UIApplication.didReceiveMemoryWarningNotification, #selector(clearMemoryCache)),
|
|
|
(UIApplication.willTerminateNotification, #selector(cleanExpiredDiskCache)),
|
|
|
(UIApplication.didEnterBackgroundNotification, #selector(backgroundCleanExpiredDiskCache))
|
|
|
]
|
|
|
#else
|
|
|
- let notifications: [(Notification.Name, Selector)] = [
|
|
|
+ notifications = [
|
|
|
(NSNotification.Name.UIApplicationDidReceiveMemoryWarning, #selector(clearMemoryCache)),
|
|
|
(NSNotification.Name.UIApplicationWillTerminate, #selector(cleanExpiredDiskCache)),
|
|
|
(NSNotification.Name.UIApplicationDidEnterBackground, #selector(backgroundCleanExpiredDiskCache))
|
|
|
]
|
|
|
#endif
|
|
|
+ #elseif os(macOS)
|
|
|
+ notifications = [
|
|
|
+ (NSApplication.willResignActiveNotification, #selector(cleanExpiredDiskCache)),
|
|
|
+ ]
|
|
|
+ #else
|
|
|
+ notifications = []
|
|
|
+ #endif
|
|
|
notifications.forEach {
|
|
|
NotificationCenter.default.addObserver(self, selector: $0.1, name: $0.0, object: nil)
|
|
|
}
|
|
|
- #endif
|
|
|
}
|
|
|
|
|
|
/// Creates an `ImageCache` with a given `name`. Both `MemoryStorage` and `DiskStorage` will be created
|