AFNetworking 2.0 queue request when device is offline with setReachabilityStatusChangeBlock does nothing

前端 未结 2 1706
走了就别回头了
走了就别回头了 2020-12-08 06:14

I\'ve been trying to come up with a solution to queue HTTP requests using AFNetworking when the device is offline, so when it goes back online the requests gets done. As far

相关标签:
2条回答
  • 2020-12-08 06:30

    You do not store manager. So it is like any local variable is deleted when leaving viewDidLoad. Store it to property or instance variable.

    0 讨论(0)
  • 2020-12-08 06:35

    You need to call startMonitoring, before you call setReachabilityStatusChangeBlock

    [manager.reachabilityManager startMonitoring];

    If you are using AFNetworking 2.0, I suggest following:

    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        DLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN:
            case AFNetworkReachabilityStatusReachableViaWiFi:
                [operationQueue setSuspended:NO];
                NSLog(@"WIFI");
                break;
            case AFNetworkReachabilityStatusNotReachable:
            default:
                [operationQueue setSuspended:YES];
                NSLog(@"offline, baby");
                break;
        }
    }];
    
    0 讨论(0)
提交回复
热议问题