diff --git a/Classes/Public/SCNetworkReachability.m b/Classes/Public/SCNetworkReachability.m index 8f596d7..c0eaaa2 100644 --- a/Classes/Public/SCNetworkReachability.m +++ b/Classes/Public/SCNetworkReachability.m @@ -97,6 +97,10 @@ - (void)observeReachabilityOnDispatchQueue:(dispatch_queue_t)queue { async_queue_block(queue, block, status); }; + if (self.isStatusValid) + { + self.observationBlock(self.status); + } } - (void)reachabilityStatusOnDispatchQueue:(dispatch_queue_t)queue @@ -104,29 +108,10 @@ - (void)reachabilityStatusOnDispatchQueue:(dispatch_queue_t)queue { if (block) { + [self updateStatusBlockWithDispatchQueue:queue block:block]; if (self.isStatusValid) { - SCNetworkStatus status = self.status; - async_queue_block(queue, block, status); - } - else - { - if (self.statusBlock) - { - void (^previousBlock)(SCNetworkStatus status) = self.statusBlock; - self.statusBlock = ^(SCNetworkStatus status) - { - previousBlock(status); - async_queue_block(queue, block, status); - }; - } - else - { - self.statusBlock = ^(SCNetworkStatus status) - { - async_queue_block(queue, block, status); - }; - } + self.statusBlock(self.status); } } } @@ -146,4 +131,25 @@ + (void)hostReachabilityStatus:(NSString *)host onDispatchQueue:(dispatch_queue_ }); } +- (void)updateStatusBlockWithDispatchQueue:(dispatch_queue_t)queue + block:(void (^)(SCNetworkStatus))block +{ + if (self.statusBlock) + { + void (^previousBlock)(SCNetworkStatus status) = self.statusBlock; + self.statusBlock = ^(SCNetworkStatus status) + { + previousBlock(status); + async_queue_block(queue, block, status); + }; + } + else + { + self.statusBlock = ^(SCNetworkStatus status) + { + async_queue_block(queue, block, status); + }; + } +} + @end