Problems with Reachability

Discussion in 'iOS Programming' started by danmwall, Feb 9, 2010.

  1. danmwall macrumors newbie

    Joined:
    Apr 13, 2009
    #1
    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:

    Can someone PLEASE help me!! :eek:
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. danmwall thread starter macrumors newbie

    Joined:
    Apr 13, 2009
    #3
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
  5. danmwall thread starter macrumors newbie

    Joined:
    Apr 13, 2009
    #5
    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!
     

Share This Page