File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -123,9 +123,14 @@ - (void)initImageDownloaders
123
123
// Make sure we support self-signed certificates we trusted before
124
124
[[SDWebImageDownloader sharedDownloader ].config setOperationClass: [NCWebImageDownloaderOperation class ]];
125
125
126
- // Set the caching path to be in our app group and limit size to 100 MB
127
- NSURL *avatarCacheURL = [[[NSFileManager defaultManager ] containerURLForSecurityApplicationGroupIdentifier: groupIdentifier] URLByAppendingPathComponent: @" AvatarCache" ];
128
- SDImageCache.defaultDiskCacheDirectory = avatarCacheURL.path ;
126
+ // Try to remove legacy avatar cache in app group
127
+ NSURL *legacyCacheURL = [[[NSFileManager defaultManager ] containerURLForSecurityApplicationGroupIdentifier: groupIdentifier] URLByAppendingPathComponent: @" AvatarCache" ];
128
+ if (legacyCacheURL != nil ) {
129
+ [[NSFileManager defaultManager ] removeItemAtURL: legacyCacheURL error: nil ];
130
+ }
131
+
132
+ // Limit the cache size to 100 MB and prevent uploading to iCloud
133
+ // Don't set the path to an app group in order to prevent crashes
129
134
[SDImageCache sharedImageCache ].config .shouldDisableiCloud = YES ;
130
135
[SDImageCache sharedImageCache ].config .maxDiskSize = 100 * 1024 * 1024 ;
131
136
Original file line number Diff line number Diff line change @@ -14,9 +14,14 @@ import Foundation
14
14
init ( ) {
15
15
let configuration = AFImageDownloader . defaultURLSessionConfiguration ( )
16
16
17
+ // Try to remove legacy ImageCache directory in app group
18
+ if let legacyCacheURL = FileManager . default. containerURL ( forSecurityApplicationGroupIdentifier: groupIdentifier) ? . appendingPathComponent ( " ImageCache " ) {
19
+ try ? FileManager . default . removeItem ( at: legacyCacheURL)
20
+ }
21
+
17
22
// In case of images we want to use the cache and store it on disk
18
23
// As we use the memory cache from AFImageDownloader, we only want disk cache here
19
- let imageCacheURL = FileManager . default. containerURL ( forSecurityApplicationGroupIdentifier : groupIdentifier ) ? . appendingPathComponent ( " ImageCache " )
24
+ let imageCacheURL = FileManager . default. urls ( for : . cachesDirectory , in : . userDomainMask ) . first ? . appendingPathComponent ( " ImageCache " )
20
25
self . cache = URLCache ( memoryCapacity: 0 , diskCapacity: 100 * 1024 * 1024 , directory: imageCacheURL)
21
26
22
27
configuration. urlCache = self . cache
You can’t perform that action at this time.
0 commit comments