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;
}
}