Network reachability

Discussion in 'Developer Services and Trade' started by angelsfan27vg, Sep 28, 2009.

  1. I am making an app that needs to be able to tell whether it can reach a network, either Wi-fi or edge or 3g. My main problem with coding things, is that I don't know where to put the lines of sample code around the ones just for my app. Can someone just do me the small favor and insert the code to determine network reachability into my app?
     
  2. xother

    xother Active Member

    Aug 18, 2009
    26
    0
    0
    It really isn't that hard to implement. Include the Reachability class from the apple example code in your project and make sure to make the following adjustments to your appDelegate.

    1) In your applicationDidFinish method, start the notification center, like

    Code:
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityNewChangedNotification object: nil];
    			
    internetReach = [[ReachabilityNew reachabilityForInternetConnection] retain];
    [internetReach startNotifer];
    [self updateReachability: internetReach];
    //internetReach is a property of the appDelegate and an instance of the Reachability class
    
    2) add the updateReachability method from the code example, but let it call your own method instead of the configureTextField method

    3) rewrite and rename the configureTextField method of the delegate so that it sets a global bool in the switch statement. You can place the global bool in a shared singleton or a class you can access in your other classes.
     

Share This Page