From 6dfd5d804ab4ac28168c68b860d3360d525e899d Mon Sep 17 00:00:00 2001 From: Dmitry Makarenko Date: Fri, 25 Nov 2016 13:50:11 +0000 Subject: [PATCH] Fixed #100 by assigning CFRetain and CFRelease function pointers to SCNetworkReachabilityContext `retain` and `release` fields. Removed `reachabilityObject` property since SCNetworkReachability takes care of the lifecycle of the object now. --- Reachability.m | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Reachability.m b/Reachability.m index 4c1c94a..2c3cebd 100644 --- a/Reachability.m +++ b/Reachability.m @@ -42,7 +42,6 @@ @interface Reachability () @property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef; @property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue; -@property (nonatomic, strong) id reachabilityObject; -(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags; -(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags; @@ -186,24 +185,16 @@ -(void)dealloc -(BOOL)startNotifier { - // allow start notifier to be called multiple times - if(self.reachabilityObject && (self.reachabilityObject == self)) - { - return YES; - } - - SCNetworkReachabilityContext context = { 0, NULL, NULL, NULL, NULL }; context.info = (__bridge void *)self; + context.retain = CFRetain; + context.release = CFRelease; if(SCNetworkReachabilitySetCallback(self.reachabilityRef, TMReachabilityCallback, &context)) { // Set it as our reachability queue, which will retain the queue if(SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, self.reachabilitySerialQueue)) { - // this should do a retain on ourself, so as long as we're in notifier mode we shouldn't disappear out from under ourselves - // woah - self.reachabilityObject = self; return YES; } else @@ -224,7 +215,6 @@ -(BOOL)startNotifier } // if we get here we fail at the internet - self.reachabilityObject = nil; return NO; } @@ -235,8 +225,6 @@ -(void)stopNotifier // Unregister target from the GCD serial dispatch queue. SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, NULL); - - self.reachabilityObject = nil; } #pragma mark - reachability tests