From a9ea132874e11dd5165db9858fad1729c272de0c Mon Sep 17 00:00:00 2001 From: mythodeia Date: Wed, 15 Jul 2015 11:04:44 +0300 Subject: [PATCH] disable iCloud backup --- SDWebImage/SDImageCache.h | 5 +++++ SDWebImage/SDImageCache.m | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index 8e08aa1..ca6033a 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -42,6 +42,11 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot */ @property (assign, nonatomic) BOOL shouldDecompressImages; +/** + * disable iCloud backup [defaults to YES] + */ +@property (assign, nonatomic) BOOL shouldDisableiCloud; + /** * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. */ diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 2202602..c197b5c 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -116,6 +116,9 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { // Set decompression to YES _shouldDecompressImages = YES; + // Disable iCloud + _shouldDisableiCloud = YES; + dispatch_sync(_ioQueue, ^{ _fileManager = [NSFileManager new]; }); @@ -237,7 +240,17 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; } - [_fileManager createFileAtPath:[self defaultCachePathForKey:key] contents:data attributes:nil]; + // get cache Path for image key + NSString *cachePathForKey = [self defaultCachePathForKey:key]; + // transform to NSUrl + NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey]; + + [_fileManager createFileAtPath:cachePathForKey contents:data attributes:nil]; + + // disable iCloud backup + if (self.shouldDisableiCloud) { + [fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil]; + } } }); }