Skip to content

Commit

Permalink
bugfix for status report
Browse files Browse the repository at this point in the history
  • Loading branch information
dustturtle committed May 17, 2018
1 parent de21b13 commit 9506f27
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions RealReachability/RealReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,24 @@ - (void)reachabilityWithBlock:(void (^)(ReachabilityStatus status))asyncHandler
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (isSuccess)
{
// no need to post the notification because the status is not changing.
ReachabilityStatus status = [self currentReachabilityStatus];

// Post the notification if the state changed here.
NSDictionary *inputDic = @{kEventKeyID:@(RREventPingCallback), kEventKeyParam:@(YES)};
[strongSelf.engine receiveInput:inputDic];
NSInteger rtn = [strongSelf.engine receiveInput:inputDic];
if (rtn == 0) // state changed & state available, post notification.
{
if ([strongSelf.engine isCurrentStateAvailable])
{
strongSelf.previousStatus = status;
__weak __typeof(self)weakSelf = strongSelf;
dispatch_async(dispatch_get_main_queue(), ^{
__strong __typeof(weakSelf)strongSelf = weakSelf;
[[NSNotificationCenter defaultCenter] postNotificationName:kRealReachabilityChangedNotification
object:strongSelf];
});
}
}

if (asyncHandler != nil)
{
Expand Down Expand Up @@ -298,19 +313,22 @@ - (void)makeDoubleCheck:(void (^)(ReachabilityStatus status))asyncHandler
__weak __typeof(self)weakSelf = self;
[self.pingChecker pingWithBlock:^(BOOL isSuccess) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
ReachabilityStatus status = [strongSelf currentReachabilityStatus];

NSDictionary *inputDic = @{kEventKeyID:@(RREventPingCallback), kEventKeyParam:@(isSuccess)};
[strongSelf.engine receiveInput:inputDic];

if (!isSuccess)
NSInteger rtn = [strongSelf.engine receiveInput:inputDic];
if (rtn == 0) // state changed & state available, post notification.
{
// Only fail make the change; then we post the fail notification.
__weak __typeof(strongSelf)deepWeakSelf = strongSelf;
dispatch_async(dispatch_get_main_queue(), ^{
__strong __typeof(deepWeakSelf)deepStrongSelf = deepWeakSelf;
[[NSNotificationCenter defaultCenter] postNotificationName:kRealReachabilityChangedNotification
object:deepStrongSelf];
});
if ([strongSelf.engine isCurrentStateAvailable])
{
strongSelf.previousStatus = status;
__weak __typeof(self)weakSelf = strongSelf;
dispatch_async(dispatch_get_main_queue(), ^{
__strong __typeof(weakSelf)strongSelf = weakSelf;
[[NSNotificationCenter defaultCenter] postNotificationName:kRealReachabilityChangedNotification
object:strongSelf];
});
}
}

if (asyncHandler != nil)
Expand Down

0 comments on commit 9506f27

Please sign in to comment.