Break retain cycle for background tasks

This commit is contained in:
Jerry Beers 2012-10-30 22:29:11 -05:00 committed by Mattt Thompson
parent 652ad787e7
commit c3bc36abd7

View file

@ -257,15 +257,16 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
[self.lock lock];
if (!self.backgroundTaskIdentifier) {
UIApplication *application = [UIApplication sharedApplication];
__unsafe_unretained typeof(self) _blockSelf = self;
self.backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
if (handler) {
handler();
}
[self cancel];
[_blockSelf cancel];
[application endBackgroundTask:self.backgroundTaskIdentifier];
self.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
[application endBackgroundTask:_blockSelf.backgroundTaskIdentifier];
_blockSelf.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
}];
}
[self.lock unlock];