Skip to content

Commit

Permalink
Don't use app-groups for caches anymore
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Sep 2, 2024
1 parent 5d30fe3 commit c6964ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions NextcloudTalk/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ - (void)initImageDownloaders
// Make sure we support self-signed certificates we trusted before
[[SDWebImageDownloader sharedDownloader].config setOperationClass:[NCWebImageDownloaderOperation class]];

// Set the caching path to be in our app group and limit size to 100 MB
NSURL *avatarCacheURL = [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupIdentifier] URLByAppendingPathComponent:@"AvatarCache"];
SDImageCache.defaultDiskCacheDirectory = avatarCacheURL.path;
// Try to remove legacy avatar cache in app group
NSURL *legacyCacheURL = [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupIdentifier] URLByAppendingPathComponent:@"AvatarCache"];
if (legacyCacheURL != nil) {
[[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:nil];
}

// Limit the cache size to 100 MB and prevent uploading to iCloud
// Don't set the path to an app group in order to prevent crashes
[SDImageCache sharedImageCache].config.shouldDisableiCloud = YES;
[SDImageCache sharedImageCache].config.maxDiskSize = 100 * 1024 * 1024;

Expand Down
7 changes: 6 additions & 1 deletion NextcloudTalk/NCImageSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import Foundation
init() {
let configuration = AFImageDownloader.defaultURLSessionConfiguration()

// Try to remove legacy ImageCache directory in app group
if let legacyCacheURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier)?.appendingPathComponent("ImageCache") {
try? FileManager.default .removeItem(at: legacyCacheURL)
}

// In case of images we want to use the cache and store it on disk
// As we use the memory cache from AFImageDownloader, we only want disk cache here
let imageCacheURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier)?.appendingPathComponent("ImageCache")
let imageCacheURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first?.appendingPathComponent("ImageCache")
self.cache = URLCache(memoryCapacity: 0, diskCapacity: 100 * 1024 * 1024, directory: imageCacheURL)

configuration.urlCache = self.cache
Expand Down

0 comments on commit c6964ca

Please sign in to comment.