[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
	localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
	Reachability* retVal = [self reachabilityWithAddress: &localWifiAddress];
	if(retVal!= NULL)
		retVal->localWiFiRef = YES;
	return retVal;

, , , , ,

3 Responses to [Reachability reachabilityForLocalWiFi] crash with OS4 SDK

  1. fellow programmer July 29, 2010 at 2:28 am #

    This happened to me with with 4.0. I never thought I would find as useful search result as finding this when searching for:

    Reachabilityinit ]: cannot init a class object.

    Thank you!

  2. Eduardo Ballesteros August 10, 2010 at 11:54 am #

    Tahnk you, but is most easy download the source code…

    The version with //[super init]; is 2.2 for this code

    Than you

    • ayn August 10, 2010 at 12:02 pm #

      word, I'm sure they have fixed it by now. I haven't looked since I pulled it from Apple.thanks!-Andrew

Leave a Reply