3

I am using SCNetworkReachabilityCreateWithName & SCNetworkReachabilityGetFlags to test for network availability in my iOS device. When I run the app in the Simulator, or run it on the device, but attached to the debugger, everything's completely cool. However, when I run the app on the test device but detached from the debugger, I get a crash. [EDIT: just realized I didn't indicate where: in the call to SCNetworkReachabilityGetFlags] The odd thing is, it doesn't happen the first time I run the check. It happens on the second check. And using a try/catch does absolutely nothing.

The crash is immediate. There is no delay while the async polling occurs and the app just times out. It's immediate.

This is completely effed. I don't understand at all why this would be occurring. I am getting ready to go to a conference to exhibit the app and its accompanying web app. I was planning on walking the floor to show it off. But now I'm basically restricted to keeping my iPhone/iPod tethered to my computer in the booth.

Any ideas? Any work-arounds that don't keep me attached to the computer? And any long-term solutions that solve this? I use this method to check for network availability every time I perform any network activity. I am syncing my data to the Cloud, and run this check each time a sync occurs. I feel this is necessary to keep the user informed if there's a sudden break in the network connection.

Help????

Here's the code snippet.

+ (BOOL) networkConnected {
SCNetworkReachabilityFlags flags = 0;
SCNetworkReachabilityRef netReachability;
BOOL retrievedFlags = NO;

BOOL reachable = NO;

netReachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [EXTERNAL_HOST UTF8String]);

@try {
    if(netReachability) {
        retrievedFlags = SCNetworkReachabilityGetFlags(netReachability, &flags);
        CFRelease(netReachability);
    }

    if(!retrievedFlags || !flags)
        reachable = NO;
    else
        reachable = YES;
} @catch (NSException *ex) {
    reachable = NO;
} @finally {
    return reachable;
}

}

Gregory Hill
  • 155
  • 1
  • 14
  • Did you ever figure this out? I'm seeing this kind of crash all of a sudden when using Hoptoad. – Christopher Pickslay Sep 30 '11 at 22:13
  • 1
    @chrispix - yes, I did. Sorry for not following up. I invoke it indirectly with: **[NSThread detachNewThreadSelector:@selector(testNetworkLevel) toTarget:self withObject:nil];** It's a threading issue. – Gregory Hill Oct 13 '11 at 19:59

0 Answers0