فهرست منبع

Remove assertion that status in callback == reachabilityManager status

The status passed in callbacks (both block and notification) is captured before the callbacks are dispatched on the main thread. It is thus possible that the reachabilityManager status change in the meantime.

Users MUST use the status parameter for the block callback or the `AFNetworkingReachabilityNotificationStatusItem` user info key for the notification.
Cédric Luthi 8 سال پیش
والد
کامیت
fb5022c073
1فایلهای تغییر یافته به همراه6 افزوده شده و 13 حذف شده
  1. 6 13
      Tests/Tests/AFNetworkReachabilityManagerTests.m

+ 6 - 13
Tests/Tests/AFNetworkReachabilityManagerTests.m

@@ -64,12 +64,9 @@
                              handler:^BOOL(NSNotification *note) {
                              handler:^BOOL(NSNotification *note) {
                                  AFNetworkReachabilityStatus status;
                                  AFNetworkReachabilityStatus status;
                                  status = [note.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
                                  status = [note.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
-                                 BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
-                                                   || status == AFNetworkReachabilityStatusReachableViaWWAN);
-
-                                 XCTAssertEqual(reachable, manager.isReachable, @"Expected status to match 'isReachable'");
-
-                                 return reachable;
+                                 BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
+                                                     || status == AFNetworkReachabilityStatusReachableViaWWAN);
+                                 return isReachable;
                              }];
                              }];
 
 
     [manager startMonitoring];
     [manager startMonitoring];
@@ -89,14 +86,10 @@
 {
 {
     __weak __block XCTestExpectation *expectation = [self expectationWithDescription:@"reachability status change block gets called"];
     __weak __block XCTestExpectation *expectation = [self expectationWithDescription:@"reachability status change block gets called"];
 
 
-    typeof(manager) __weak weakManager = manager;
     [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
     [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
-        BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
-                          || status == AFNetworkReachabilityStatusReachableViaWWAN);
-
-        XCTAssertEqual(reachable, weakManager.isReachable, @"Expected status to match 'isReachable'");
-
-        if (reachable) {
+        BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
+                            || status == AFNetworkReachabilityStatusReachableViaWWAN);
+        if (isReachable) {
             [expectation fulfill];
             [expectation fulfill];
             expectation = nil;
             expectation = nil;
         }
         }