Break retain cycle for background tasks
This commit is contained in:
parent
652ad787e7
commit
c3bc36abd7
1 changed files with 4 additions and 3 deletions
|
|
@ -257,15 +257,16 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
[self.lock lock];
|
[self.lock lock];
|
||||||
if (!self.backgroundTaskIdentifier) {
|
if (!self.backgroundTaskIdentifier) {
|
||||||
UIApplication *application = [UIApplication sharedApplication];
|
UIApplication *application = [UIApplication sharedApplication];
|
||||||
|
__unsafe_unretained typeof(self) _blockSelf = self;
|
||||||
self.backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
|
self.backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handler();
|
handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
[self cancel];
|
[_blockSelf cancel];
|
||||||
|
|
||||||
[application endBackgroundTask:self.backgroundTaskIdentifier];
|
[application endBackgroundTask:_blockSelf.backgroundTaskIdentifier];
|
||||||
self.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
|
_blockSelf.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue