Reachability responding with wrong status code in iOS 7 iphone 5
Asked Answered
D

5

5

I am facing weird problem on iPhone 5 with iOS 7, i have tested same code with other devices like iPad1, 2, 3 and iPhone 4, 4s etc. with different iOS combination including iOS 7.

Problem :

When i turn on airplane mode i do get reachability notification as expected with status NotReachable but immediately after that app receives notification with status code ReachableViaWWAN which 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 log before switch which is returning status as ReachableViaWWAN in airplane mode..

Possible workaround could be:

Add case for ReachableViaWWAN and check host reachable in that case. And return BOOL value accordingly.

Anyone faced similar problem ?? i have searched but haven't found similar scenario.

Thanks in advance !!

Divulgate answered 13/11, 2013 at 9:11 Comment(0)
M
10

I had the same problem. The solution is to check the flag isConnectionRequired. The documentation says:

WWAN may be available, but not active until a connection has been established.

Code

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

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

} else if((ReachableViaWiFi == reachability.currentReachabilityStatus) || (ReachableViaWWAN == reachability.currentReachabilityStatus)){
    isServerAvailable = YES;
}
Mighell answered 29/1, 2014 at 14:11 Comment(0)
B
2

The old Reachability files are no good. Apple has updated their reachability files.

Check here.

https://developer.apple.com/Library/ios/samplecode/Reachability/Introduction/Intro.html

Download here.

https://developer.apple.com/Library/ios/samplecode/Reachability/Reachability.zip

Bailey answered 23/5, 2014 at 13:53 Comment(2)
Using the latest code from Apple solved WWAN issues for me. Thanks.Audly
Fixed it for me tooCommission
S
1

I encountered this problem and found a solution here. Basically for some reason it's possible to get ReachableViaWWAN even when in airplane mode. However, there's another flag that will indicate whether a connection must first be established. This is the kSCNetworkReachabilityFlagsConnectionRequired flag which has a nice helper method in the Reachability class called connectionRequired

Subhead answered 7/1, 2014 at 13:9 Comment(0)
C
0

Reachability classes can give strange results if you are using the Network Link Conditioner tool provided by Apple.

Cain answered 20/8, 2014 at 18:40 Comment(1)
Please add your post as a comment if it is not intended at answering the question.Compel
C
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;


    }

}
Canon answered 9/10, 2014 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.