★ TouchArcade needs your help. Click here to support us on Patreon.

Network reachability

09-28-2009, 03:37 PM
#1
Joined: Apr 2009
Location: California, United States
Posts: 66
Send a message via AIM to angelsfan27vg Send a message via Yahoo to angelsfan27vg Send a message via Skype™ to angelsfan27vg
Network reachability

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?

Iron Gate Studios: www.irongatestudios.com
Check out our apps on the App Store!
Plus+/Gameloft Live/OpenFeint: angelsfan27vg
09-28-2009, 04:47 PM
#2
Joined: Aug 2009
Posts: 26
Quote:
Originally Posted by angelsfan27vg View Post
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?
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.

Lunarcy a really challenging retro looking arcade game.