Skip to content

Commit 9506f27

Browse files
committed
bugfix for status report
1 parent de21b13 commit 9506f27

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

RealReachability/RealReachability.m

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,24 @@ - (void)reachabilityWithBlock:(void (^)(ReachabilityStatus status))asyncHandler
188188
__strong __typeof(weakSelf)strongSelf = weakSelf;
189189
if (isSuccess)
190190
{
191-
// no need to post the notification because the status is not changing.
191+
ReachabilityStatus status = [self currentReachabilityStatus];
192+
193+
// Post the notification if the state changed here.
192194
NSDictionary *inputDic = @{kEventKeyID:@(RREventPingCallback), kEventKeyParam:@(YES)};
193-
[strongSelf.engine receiveInput:inputDic];
195+
NSInteger rtn = [strongSelf.engine receiveInput:inputDic];
196+
if (rtn == 0) // state changed & state available, post notification.
197+
{
198+
if ([strongSelf.engine isCurrentStateAvailable])
199+
{
200+
strongSelf.previousStatus = status;
201+
__weak __typeof(self)weakSelf = strongSelf;
202+
dispatch_async(dispatch_get_main_queue(), ^{
203+
__strong __typeof(weakSelf)strongSelf = weakSelf;
204+
[[NSNotificationCenter defaultCenter] postNotificationName:kRealReachabilityChangedNotification
205+
object:strongSelf];
206+
});
207+
}
208+
}
194209

195210
if (asyncHandler != nil)
196211
{
@@ -298,19 +313,22 @@ - (void)makeDoubleCheck:(void (^)(ReachabilityStatus status))asyncHandler
298313
__weak __typeof(self)weakSelf = self;
299314
[self.pingChecker pingWithBlock:^(BOOL isSuccess) {
300315
__strong __typeof(weakSelf)strongSelf = weakSelf;
316+
ReachabilityStatus status = [strongSelf currentReachabilityStatus];
301317

302318
NSDictionary *inputDic = @{kEventKeyID:@(RREventPingCallback), kEventKeyParam:@(isSuccess)};
303-
[strongSelf.engine receiveInput:inputDic];
304-
305-
if (!isSuccess)
319+
NSInteger rtn = [strongSelf.engine receiveInput:inputDic];
320+
if (rtn == 0) // state changed & state available, post notification.
306321
{
307-
// Only fail make the change; then we post the fail notification.
308-
__weak __typeof(strongSelf)deepWeakSelf = strongSelf;
309-
dispatch_async(dispatch_get_main_queue(), ^{
310-
__strong __typeof(deepWeakSelf)deepStrongSelf = deepWeakSelf;
311-
[[NSNotificationCenter defaultCenter] postNotificationName:kRealReachabilityChangedNotification
312-
object:deepStrongSelf];
313-
});
322+
if ([strongSelf.engine isCurrentStateAvailable])
323+
{
324+
strongSelf.previousStatus = status;
325+
__weak __typeof(self)weakSelf = strongSelf;
326+
dispatch_async(dispatch_get_main_queue(), ^{
327+
__strong __typeof(weakSelf)strongSelf = weakSelf;
328+
[[NSNotificationCenter defaultCenter] postNotificationName:kRealReachabilityChangedNotification
329+
object:strongSelf];
330+
});
331+
}
314332
}
315333

316334
if (asyncHandler != nil)

0 commit comments

Comments
 (0)