How to Download the Reachability Sample - dummies

How to Download the Reachability Sample

By Neal Goldstein, Dave Wilson

Apple provides a sample application called Reachability that shows how to determine whether you have an Internet connection for your iOS app (as well as quite a bit of additional network information). Here’s how to use code from that valuable sample program:

  1. Download the Reachability sample from Apple by clicking Sample Code.

  2. Type Reachability in the Search field.

  3. Click the Reachability project in the search results, and in the iOS Developer Library window that appears, click the Download Sample Code button.

  4. In Safari downloads, double-click the Reachability folder to open it.

  5. Open the disclosure triangle next to the Classes folder (or open the folder) and drag the Reachability.m and Reachability.h files into your project.

    You can put them in your Supporting Files group just to keep them out of the way.

  6. Select the check box in front of Road Trip in the Add to Targets section.

    Be sure to select the Copy Items into Destination Group’s Folder option (if it isn’t already selected).

In order for you to be able to use this code, you need to add the SystemConfiguration framework. To do so, follow these steps:

  1. In the Project navigator, select the project icon (in this case, RoadTrip) at the top of the Project navigator content area to display the Project editor.

  2. In the Targets section in the Project editor, select RoadTrip.

  3. On the Summary tab, scroll down to the Linked Frameworks and Libraries section.

  4. Expand the Linked Frameworks and Libraries section if it isn’t already expanded (see the figure) by clicking the disclosure triangle.

    The Xcode workspace.

  5. Click the + (plus sign) button underneath the list of current project frameworks.

    A list of frameworks appears.

  6. Scroll down and select SystemConfiguration.framework, as shown in this figure.

    An open framework in Xcode's workspace.

  7. Click the Add button.

    You’ll see the framework added to the Linked Frameworks and Libraries section.

  8. Close the Linked Frameworks and Libraries section.

  9. In the Project navigator (don’t do this from the Linked Frameworks and Libraries section!), drag the SystemConfiguration.framework file (you can see it at the top of the Project Navigator in the figure) to the Frameworks group, as shown.

    The project navigator in Xcode.

You can also add a framework by clicking the Build Phases tab in the Project editor, expanding the Link Binary with Libraries section, and following the same procedure.