Tag Archives: reachability

[Reachability reachabilityForLocalWiFi] crash with OS4 SDK

If you’re using Apple’s reachability framework and compiling with OS4 beta SDK, you might get a crash like this:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[Reachability<0xf37d0> init]: cannot init a class object.'

You can fix it by commenting out the [super init] line in + (Reachability*) reachabilityForLocalWiFi in Reachability.m:

+ (Reachability*) reachabilityForLocalWiFi;
{
	//[super init];
	struct sockaddr_in localWifiAddress;
	bzero(&localWifiAddress, sizeof(localWifiAddress));
	localWifiAddress.sin_len = sizeof(localWifiAddress);
	localWifiAddress.sin_family = AF_INET;
	// IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
	localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
	Reachability* retVal = [self reachabilityWithAddress: &localWifiAddress];
	if(retVal!= NULL)
	{
		retVal->localWiFiRef = YES;
	}
	return retVal;
}