Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Commit

Permalink
Merge commit 'e995a038623fe45fb0495450e86cfffbe5639f1d' into temporar…
Browse files Browse the repository at this point in the history
…y-state-fixes
  • Loading branch information
zbowling committed May 13, 2012
2 parents fb9f625 + e995a03 commit 2067142
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
24 changes: 13 additions & 11 deletions AFNetworking/AFHTTPRequestOperation.m
Expand Up @@ -56,30 +56,32 @@ - (id)initWithRequest:(NSURLRequest *)request {
//by default we will use the queue that created the request.
self.callbackQueue = dispatch_get_current_queue();

__weak AFHTTPRequestOperation *weakSelf = self;
super.completionBlock = ^ {
if (_completionBlock) {
_completionBlock(); //call any child completion blocks that may have been passed in that they may want to run
AFHTTPRequestOperation *strongSelf = weakSelf;
if (strongSelf->_completionBlock) {
strongSelf->_completionBlock(); //call any child completion blocks that may have been passed in that they may want to run
}

if ([self isCancelled]) {
if ([strongSelf isCancelled]) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[self endBackgroundTask];
[strongSelf endBackgroundTask];
#endif
self.finishedBlock = nil;
strongSelf.finishedBlock = nil;
return;
}

if (self.finishedBlock) {
dispatch_sync(self.callbackQueue, ^(void) {
self.finishedBlock();
if (strongSelf.finishedBlock) {
dispatch_sync(strongSelf.callbackQueue, ^(void) {
strongSelf.finishedBlock();
});
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[self endBackgroundTask];
[strongSelf endBackgroundTask];
#endif
self.finishedBlock = nil;
strongSelf.finishedBlock = nil;
} else {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[self endBackgroundTask];
[strongSelf endBackgroundTask];
#endif
}
};
Expand Down
10 changes: 7 additions & 3 deletions AFNetworking/AFURLConnectionOperation.m
Expand Up @@ -256,8 +256,9 @@ - (void)setCompletionBlock:(void (^)(void))block {
} else {
__weak id _blockSelf = self;
[super setCompletionBlock:^ {
id strongSelf = _blockSelf;
block();
[_blockSelf setCompletionBlock:nil];
[strongSelf setCompletionBlock:nil];
}];
}
}
Expand Down Expand Up @@ -467,8 +468,11 @@ - (NSCachedURLResponse *)connection:(NSURLConnection *)__unused connection
if ([self isCancelled]) {
return nil;
}

if (self.cacheStoragePolicy == AFURLCacheStorageDefault

if (self.cacheStoragePolicy == AFURLCacheStorageNotAllowed) {
return nil;
}
else if (self.cacheStoragePolicy == AFURLCacheStorageDefault
|| self.cacheStoragePolicy == cachedResponse.storagePolicy) {
return cachedResponse;
}
Expand Down

0 comments on commit 2067142

Please sign in to comment.