I'm using Reachability on my project and when I tried to get information about connection type I get this error.
*** Assertion failure in -[Reachability currentReachabilityStatus],/myProjectPath/Reachability.m:530
2012-04-03 21:25:45.619 Traffic[7862:11603] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'currentNetworkStatus called with NULL reachabilityRef'
I don't know what is wrong with my code. I put the same code as in ReachabilityAppDelegate to get connection status.
my code:
// get type of user connection
NSString* statusString= @"NA";
Reachability *curReach = [[Reachability alloc] init];
NetworkStatus netStatus = [curReach currentReachabilityStatus];
BOOL connectionRequired= [curReach connectionRequired];
switch (netStatus)
{
case NotReachable:
{
statusString = @"NA";
//Minor interface detail- connectionRequired may return yes, even when the host is unreachable. We cover that up here...
connectionRequired= NO;
break;
}
case ReachableViaWWAN:
{
statusString = @"WWAN";
break;
}
case ReachableViaWiFi:
{
statusString= @"WIFI";
break;
}
}
I had the same problem.
I was checking for if reachability.currentReachabilityStatus() == NotReachable
before doing
reachability = Reachability.forInternetConnection()
reachability.startNotifier()
The issues is that you're asking for a status before you start the notifier, and the _reachabilityRef
is nil.
Make sure you do the calls in their needed order. first start notifier, and then only after that check/ask for a status.
check for:
//Called by Reachability whenever status changes.
- (void) reachabilityChanged: (NSNotification* )note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
in the app delegate. The NSParameterAssert causes the crash in my case