use the weakself/strongself pattern to fix AFHTTPClient not being released
see AFNetworking issue #581
This commit is contained in:
parent
30523b1b73
commit
e549ee33a9
@ -335,11 +335,17 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {}
|
||||
}
|
||||
|
||||
self.networkReachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [[self.baseURL host] UTF8String]);
|
||||
|
||||
|
||||
__weak AFHTTPClient *weakSelf = self;
|
||||
AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status){
|
||||
self.networkReachabilityStatus = status;
|
||||
if (self.networkReachabilityStatusBlock) {
|
||||
self.networkReachabilityStatusBlock(status);
|
||||
__strong AFHTTPClient *strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
// the weak ref is gone, depart this block
|
||||
return;
|
||||
}
|
||||
strongSelf.networkReachabilityStatus = status;
|
||||
if (strongSelf.networkReachabilityStatusBlock) {
|
||||
strongSelf.networkReachabilityStatusBlock(status);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user