0

Possible Duplicate:
How to check for an active Internet Connection on iPhone SDK?

I need to check the internet reachability before sending a request to fetch something remotely. I googles, and found several SO questions relating to this. But i need to check internet connectivity for iOS4 and iOS5. How can i do that programatically ?

2.) For example say i am downloading a big file (when there was internet). and suddenly the Internet goes down (Then the app might crash). So how can i avoid this ?

Community
  • 1
  • 1
sharon
  • 580
  • 12
  • 28
  • 1
    The Apple's Reachability class is the answer, as you've seen in the link you are referring to. – Macmade Jan 13 '12 at 18:00
  • The problem is, if it'll work for iOS 5. if you look close at @AndrewZimmer's answer he has not used Reachability class in his code. And he has tested it on iOS5. I need a method that will work both for iOS 4 & 5. – sharon Jan 13 '12 at 18:03
  • It works very well on iOS 5. Just try, and you'll see by yourself. – Macmade Jan 13 '12 at 18:08

1 Answers1

1

Download Reachability from Apple Site

Reachability *reachability = [Reachability reachabilityForInternetConnection];
remoteHostStatus = [reachability currentReachabilityStatus];

if (remoteHostStatus != NotReachable) {
     // do work here if the user has a valid connection
}
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
sonics876
  • 947
  • 2
  • 13
  • 31
  • 2
    When providing an answer, please pay attention to formatting... At least... – Macmade Jan 13 '12 at 18:03
  • Will this work for both iOS4 & 5 ? because the ref doc hasn't mentioned anything about iOS5. it talks about iOS 4 but not 5. – sharon Jan 13 '12 at 18:05