3

Got a weird bug here. This only manifests when the iOS Device is being used exclusively on 3G/4G networks. i.e. if over WiFi - no bug and it all works fine.

- ( BOOL ) isInternetAccessAvailable
{
    CFNetDiagnosticRef diag;

    diag = CFNetDiagnosticCreateWithURL ( NULL, ( __bridge  CFURLRef )[NSURL URLWithString:@"www.apple.com"] );

    CFNetDiagnosticStatus status;

    status = CFNetDiagnosticCopyNetworkStatusPassively ( diag, NULL );

    CFRelease ( diag );

    if ( status == kCFNetDiagnosticConnectionUp )
    {
        return YES;
    }
    else
    {
        NSString * title   = @"No Internet Connection";
        NSString * message = @"Please ensure you have an Internet Connection.";

        [self showAlertWithTitle:title andMessage:message];

        return NO;
    }
}

Okay, so I have the above method that gets called before I try and load data into a UIWebView.

As I said - over a WiFi network, this works perfectly.

If WiFi is turned off (or unavailable / not connected) and the device is using a SIM for 3G/4G networks.

the line where is calls:

status = CFNetDiagnosticCopyNetworkStatusPassively ( diag, NULL );

returns a long equivalent to:

kCFNetDiagnosticConnectionDown

So therefore my test fails and I display a warning UIAlertView to the user.

But the network is there! If I change the test line to this:

if ( ( status == kCFNetDiagnosticConnectionUp ) || ( status == kCFNetDiagnosticConnectionDown ) )

It works over 3G/4G and downloads the web page - so the device or network isn't at fault.

But the call to CFNetDiagnosticCopyNetworkStatusPassively is failing only on 3G/4G.

Any ideas?

This has just been found in an app I recently expedited into the App Store to meet advertising and merchandising deadlines and if there is a fault in my code - I need this fixed and resubmitted asap.

iOSProgrammingIsFun
  • 1,343
  • 1
  • 13
  • 28

2 Answers2

4

Confirmed bug by Apple.

Dupe if you want: Bug ID# 12443370

iOSProgrammingIsFun
  • 1,343
  • 1
  • 13
  • 28
1

You can use this to check connexion

How to check for an active Internet connection on iOS or OSX?.

cannyboyn answer for synchronous version : Take Reachability.h and Reachability.m in https://github.com/tonymillion/Reachability

#import "Reachability.h"

- (BOOL)connected 
{
    Reachability *reachability = [Reachability reachabilityForInternetConnection];  
    NetworkStatus networkStatus = [reachability currentReachabilityStatus]; 
    return !(networkStatus == NotReachable);
}
Community
  • 1
  • 1
Anthone
  • 2,000
  • 19
  • 23
  • That's not the point - Reachability is one way of doing this check. The point is that the above code is perfectly valid and works in all iOS versions APART FROM 6.0. This has been verified with Apple and logged as a bug as requested by them. – iOSProgrammingIsFun Oct 19 '12 at 14:33