6

Does anyone know if version 2.2 (the latest) of Apple's iOS 'Reachability' example code will run on iOS 3.0? I want to support iOS 3.0, and Reachability.h and .m is the first non framework code I'm using in my app. In my own code I usually read the docs for all methods I use, and use respondsToSelector: to implement methods that won't run on 3.0. When people use third party code, how do they confirm which iOS it supports without checking every method individually against the docs?

Alternatively, does anyone know how I can get my hands on the old version of the example code? (Reachability version 2.1 might help.)

MattyG
  • 8,449
  • 6
  • 44
  • 48
  • I used Reachability successfully on iOS 3.1 until Xcode 4. It failed under Xcode 4, but that's probably a code generation problem. I don't know iOS 3.0, though; I'd advise you to just try it. That said, Reachability is some of the ugliest code I've seen on iOS, and the core frameworks it calls are pretty simple to use. Copy the big IF and you're nearly done. – Steven Fisher Mar 31 '11 at 02:32
  • I recently had to use reachability for a Mac app running the latest version of OSX and went through all of reachability to plucked out what I needed. It's not a difficult task to do. – David Mar 31 '11 at 02:35
  • Thanks for your suggestions guys. I reviewed the Reachability sample code and it's methods, but it was kinda messy, and overkill for what I was trying to achieve. I ended up using NSURLConnection to simply attempt to connect to the host, and then listened for the callbacks for the page loading or failing. – MattyG Apr 04 '11 at 02:58
  • Using NSURLConnection I was able to continue to support iOS 3.0 too =). – MattyG Apr 04 '11 at 02:59
  • I am using the reachability class from http://blog.ddg.com/?p=24, which is an improved version of Apples implementation with more features. – Martin Wickman Apr 12 '11 at 11:58
  • @Matt & @Martib can you please post your comments in **Your Answer**. Because your comments are legit answer. This way we can up vote and close this question. Thank you. – Black Frog Apr 16 '11 at 14:29

1 Answers1

1

I don't mean to snipe an answer from @Matt and @Martin, but I feel like this question deserves an answer for posterity. If they come back and post their comments as answers please feel free to accept them.

Anyway, my own answer is that I would highly advise against using Apple sample projects directly in a production application, especially Reachability. Many of their examples are badly written and, as you've noticed, outdated. I've filed a lot of bugs against them without many results.

That said, one other point is that you should really think twice about relying on Reachability for control logic. If you just want to notify the user when their connection changes or something, okay. But don't rely on what Reachability says to decide whether to try communicating with the network or not. It's often wrong about your network status. Just open up a connection, and if it succeeds great, otherwise you'll get an error response letting you know there's no connection.

EDIT - Regarding your other question about how to tell what IOS a third party app supports. The answer is, unless they've documented it, you might not be able to. Best indicator is usually taking a look at the build target's "Base SDK" and "iOS Deployment Target" settings. Base SDK will be the latest iOS version they've built against, and Deployment Target will be the earliest iOS version they support.

Cheers

DougW
  • 28,776
  • 18
  • 79
  • 107
  • Thanks for the answers Doug. I abandoned Reachability in favor for the NSURLConnection trial and error solution. Much clearer, and I didn't have to use the messy Reachability code sample. – MattyG Apr 19 '11 at 00:16
  • @Matt - Cool, glad to hear it. That's definitely a better approach. – DougW Apr 19 '11 at 00:51
  • Just wanted to second the "don't ship with Reachability" and "be careful with sample project code" sentiments. FWIW, I did manage to get Reachability working in a new project before I realized I didn't need to do it Apple's way (newbie, c'est moi). It was obviously even to me inelegant and difficult to understand. – Mark Sep 18 '12 at 16:32