Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Option to turn off background caching

  • Loading branch information...
commit 8302f4dd2709d6d454f63cab67498e3c6663828c 1 parent 3a83601
Marcus S. Zarra authored
Showing with 15 additions and 1 deletion.
  1. +2 −0  ZSAssetManager.h
  2. +13 −1 ZSAssetManager.m
View
2  ZSAssetManager.h
@@ -37,6 +37,8 @@
@interface ZSAssetManager : NSObject
+@property (nonatomic, assign, getter=allowBackgroundCaching) BOOL backgroundCaching;
+
- (UIImage*)imageForURL:(NSURL*)url;
- (NSURL*)localURLForAssetURL:(NSURL*)url;
View
14 ZSAssetManager.m
@@ -72,6 +72,7 @@ - (NSOperationQueue*)assetQueue;
@implementation ZSAssetManager
+@synthesize allowOSBackgroundCaching;
@synthesize pendingCacheItems;
@synthesize totalDownload;
@synthesize cachePopulationIdentifier;
@@ -82,8 +83,11 @@ - (id)init
{
self = [super init];
+ // TODO: Is there a way to avoid object:nil?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(flushMemoryCaches:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(flushMemoryCaches:) name:UIApplicationDidReceiveMemoryWarningNotification object:[UIApplication shared]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enteringBackground:) name:UIApplicationDidEnterBackgroundNotification object:[UIApplication shared]];
[self performSelector:@selector(loadPersistentCacheLists) withObject:nil afterDelay:1.0];
@@ -311,6 +315,14 @@ - (void)cacheOperationFailed:(ZSURLConnectionDelegate*)delegate
#pragma mark -
#pragma mark Notifications
+- (void)enteringBackground:(NSNotification*)notification
+{
+ DLog(@"object %@", [[notification object] class]);
+ if ([self allowBackgroundCaching]) return;
+
+ [[self assetQueue] cancelAllOperations];
+}
+
- (void)reachabilityChanged:(NSNotification*)notification
{
NetworkStatus status = [[ZSReachability reachabilityForInternetConnection] currentReachabilityStatus];

0 comments on commit 8302f4d

Please sign in to comment.
Something went wrong with that request. Please try again.