Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

danmwall

macrumors newbie
Original poster
Apr 13, 2009
17
0
I know there are other threads on this, but I just can't get this working. I need to check to see if a device has an internet connection, so I am using the Reachability code from the Apple sample.

I imported Reachability.h and .m into my project and now I am trying to execute the following code:

Code:
	Reachability *r = [[Reachability reachabilityForInternetConnection] retain];
	
	NetworkStatus internetStatus = [r currentReachabilityStatus];
	
	if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
	{
		UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network for location finding to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
		[myAlert show];
		[myAlert release];
	}

It compiles fine, but I get a run time error when I attempt to execute the first line. Here is the error:

2010-02-09 23:10:03.594 MyiPhoneApp[3170:207] *** +[Reachability reachabilityForInternetConnection]: unrecognized selector sent to class 0x1b650
2010-02-09 23:10:03.605 MyiPhoneApp[3170:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[Reachability reachabilityForInternetConnection]: unrecognized selector sent to class 0x1b650'
2010-02-09 23:10:03.613 MyiPhoneApp[3170:207] Stack: (
864992541,
859229716,
864996485,
864492313,
864454720,
17989,
26151,
864749711,
839231364,
839231212,
839231156,
839230220,
839233420,
839227648,
839225236,
839206800,
839205012,
875886564,
864740651,
864738335,
875880904,
838872112,
838865456,
11877,
11740
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
(gdb)

Can someone PLEASE help me!! :eek:
 
You are sending the Class Reachability the message reachabilityForInternetConnection. I'm pretty sure that is wrong, especially as you then try and retain the result.

Re-read on the difference between class and instance methods.
 
Well, I figured this out and I really don't understand what happened. I noticed there was a warning right in the middle of a block of comments. I deleted the comments, and now all is well! Go figure!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.