Skip to content

Commit

Permalink
Fixed potential missing call of 'observation block'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Belkevich committed Feb 26, 2015
1 parent f4b694f commit b09c953
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions Classes/Public/SCNetworkReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,21 @@ - (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
callback:(void (^)(SCNetworkStatus))block
{
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);
}
}
}
Expand All @@ -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

0 comments on commit b09c953

Please sign in to comment.