Skip to content

Commit a9ea132

Browse files
committed
disable iCloud backup
1 parent c68d585 commit a9ea132

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

SDWebImage/SDImageCache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
4242
*/
4343
@property (assign, nonatomic) BOOL shouldDecompressImages;
4444

45+
/**
46+
* disable iCloud backup [defaults to YES]
47+
*/
48+
@property (assign, nonatomic) BOOL shouldDisableiCloud;
49+
4550
/**
4651
* The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
4752
*/

SDWebImage/SDImageCache.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ - (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory
116116
// Set decompression to YES
117117
_shouldDecompressImages = YES;
118118

119+
// Disable iCloud
120+
_shouldDisableiCloud = YES;
121+
119122
dispatch_sync(_ioQueue, ^{
120123
_fileManager = [NSFileManager new];
121124
});
@@ -237,7 +240,17 @@ - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate image
237240
[_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL];
238241
}
239242

240-
[_fileManager createFileAtPath:[self defaultCachePathForKey:key] contents:data attributes:nil];
243+
// get cache Path for image key
244+
NSString *cachePathForKey = [self defaultCachePathForKey:key];
245+
// transform to NSUrl
246+
NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey];
247+
248+
[_fileManager createFileAtPath:cachePathForKey contents:data attributes:nil];
249+
250+
// disable iCloud backup
251+
if (self.shouldDisableiCloud) {
252+
[fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
253+
}
241254
}
242255
});
243256
}

0 commit comments

Comments
 (0)