Reachability reach with incorrect status code in iOS 7 iphone 5

I ran into a strange problem on iPhone 5 with iOS 7, I had the same code with other devices like iPad1, 2, 3 and iPhone 4, 4, etc. with another combination of iOS, including iOS 7.

Problem:

When I turn on airplane mode, I receive a notification of achievement, as expected, with a status NotReachable, but immediately after this application receives a notification with a status ReachableViaWWANthat is not expected.

Code:

+(BOOL)checkReachability
{
    Reachability* internetReachable = [Reachability reachabilityForInternetConnection];
    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
    switch (internetStatus)

    {
        case NotReachable:
        {
            DebugLog(@"The internet is down.");
            return NO;
            break;
        }
        default:
            return YES;
            break;
    }
    return YES;
}

I added a log before switching, which returns the status ReachableViaWWANin flight mode.

A possible workaround might be:

Add case for ReachableViaWWANand check host availability in this case. And return the BOOL value accordingly.

- ? , .

!

+4
5

. , isConnectionRequired. :

WWAN , , .

BOOL isServerAvailable;
Reachability *reachability = [Reachability reachabilityForInternetConnection];

if ((reachability.isConnectionRequired) || (NotReachable == reachability.currentReachabilityStatus)) {
    isServerAvailable = NO;

} else if((ReachableViaWiFi == reachability.currentReachabilityStatus) || (ReachableViaWWAN == reachability.currentReachabilityStatus)){
    isServerAvailable = YES;
}
+9

. , - ReachableViaWWAN . , , . kSCNetworkReachabilityFlagsConnectionRequired, Reachability connectionRequired

+1

, Network Link Conditioner, Apple.

0
 - (void)handleReachability:(Reachability *)reachability
{
    NetworkStatus netStatus = [reachability currentReachabilityStatus];
    BOOL connectionRequired = [reachability connectionRequired];
    NSString* statusString = @"";

    switch (netStatus)
    {
        case NotReachable:
        {

            if (connectionRequired) {
                [TSMessage setDefaultViewController:[UIApplication sharedApplication].keyWindow.rootViewController];

                [TSMessage showNotificationWithTitle:NSLocalizedString(@"Something failed", nil)
                                            subtitle:NSLocalizedString(@"The internet connection seems to be down. Please check that!", nil)
                                                type:TSMessageNotificationTypeError];
            }

            connectionRequired = NO;
            break;
        }
        default:
            break;


    }

}
0

All Articles