Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:53:27+00:00 2026-05-25T00:53:27+00:00

What is the advantage of the using Reachability over the code below? I feel

  • 0

What is the advantage of the using Reachability over the code below? I feel that Reachability has a huge amount of code, but if it’s better in any way, then I’d use that instead.

NSString *connectionString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"]];

if ([connectionString length] == 0) {

    //No connection

}

Now granted, if Google ever went down then this wouldn’t work. But there’s literally no chance of that happening. What do you think? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:53:27+00:00Added an answer on May 25, 2026 at 12:53 am

    This is actually quite a good question – so good that I actually use it in iOS developer interviews when my company is recruiting:

    Why is Apple’s reachability example hundreds of lines long, when you can just use a single line to check if a URL is responsive?

    Firstly, network reachability is actually very, very complicated. It’s much more than simply testing for a URL. Think about the following examples:

    • The user is on 3G, but has used up their data allowance, so every
      request redirects to the carrier’s site.

    • The user is connected to a public WiFi network that requires
      authentication / login, so the request redirects to a log in page

    The last example is incredibly common – it happens all the time. But if you used initWithContentsOfURL your app would imagine you had connectivity, when in fact you didn’t: you would simply have been returned the contents of the page the network had redirected you to.

    This is one reason why Apple’s code is more complex than you might at first think it needs to be. You shouldn’t just be asking “can I reach this URL”, but “is the data being returned from this URL what I expect it to be“.

    But that’s really just the tip of the iceberg. Reachability does a lot more besides that – for example, I might have an app that needs to download a lot of information, say 50MB worth. It would be a bad idea to simply download 50MB of data if the user was on a 3G connection without their consent – especially if they are roaming, or on a restricted data plan. So Reachability will also tell you what type of connection the user is on: EDGE, 3G, WiFi, etc (*NB: see the note below, this is probably not the best advice).

    The ReadMe.txt inside Reachability will tell you a little more about what the code can and can’t do.

    Unfortunately, there are all too many people online who don’t realise that there are many everyday scenarios where initWithContentsOfURL will return a valid response but the user won’t have connectivity. [Blog posts like this][1] get indexed in Google, and people assume it’s an acceptable substitute: it’s not!

    One of the reasons I ask this question when recruiting is it can show a developer is not just thinking inside the box – like you and many other developers, my first reaction when I saw the Reachability sample code was “wow, this seems way too complicated for something that’s very simple”. But hopefully this answer will have gone some way to convincing you otherwise.


    Edit: Definitely take note of Steven’s comments below. He raises some points that my answer hadn’t considered (i.e., MiFi hotspots), and makes a valid case that Reachability isn’t necessarily the peak of coding heaven it code be. In many cases developers will modify Reachability with their own improvements and the like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any advantage over using a class over a struct in cases such
Is there any advantage in using one over the other? Should I use the
Is there any performance advantage to using lists over dictionaries over tuples in Python?
is there any advantage of using your own type identifier over RTTI? e.g. class
Is there any advantage to using Ajax to get data formatted as XML over
I'm wondering if there is any particular performance advantage in using LIKE over NOT
Are there any advantages of using one over the other besides readability?
Is there any advantage to using __construct() instead of the class's name for a
Is there any advantage of using java.util.concurrent.CountdownLatch instead of java.util.concurrent.Semaphore ? As far as
Is there any advantage of using int vs varbinary for storing bit masks in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.