Reachability.h

Discussion in 'iOS Programming' started by larswik, Apr 20, 2012.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    I finished my app last week and then went to read through what Apple wants you to do before submitting it. That was a mistake, I should have read that stuff first and would have caught a bunch of things I did wrong like using Vimeo instead HTTP Live Stream for my video.

    The last part is to test to see if an internet connection exists. So I downloaded the Reachability class from the Apple sample code.

    In the sample Apple provided there are a lot of items (photo included). After looking at everything I see the only thing I need to import in to my project are the,

    Reachability.h
    Reachability.m


    and instantiate an object from that Class. I don't think I need the the ReachabilityAppDelegate.h or .m and those are used for the demo project?

    Thanks.
     

    Attached Files:

  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    There is probably some code in ReachabilityAppDelegate that you'll want to incorporate into your own appDelegate.
     
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    Thanks Dejo, I brought in the Reachability.h and .m only to find out that it is not completable with ARC.

    I did some more research and found that someone wrote as a replacement for that Class that covered ARC

    https://github.com/tonymillion/Reachability

    I am trying it now.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    You also have the option to flag files as not needing ARC. This is suitable for older libraries that don't have new versions but you still want to use. More info here: How can I disable ARC for a single file in a project?
     
  5. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    Good to know. I like ARC but I am also glad I got a taste of doing my own memory management on a few projects. I think everyone starting to program should do projects without ARC till they get the hang of memory management.
     
  6. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #6
    I posted an updated reachability that supported arc in the apple forums. Not sure if it's been purged but you may want to try there.
     
  7. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #7
    I just implemented this into a project this week. It's easy to work around the ARC issue.

    1. Click on the target.
    2. Choose the Build Phases tab.
    3. Reveal the Compile Sources by clicking on the triangle.
    4. Double click the Reachability.m file.
    5. In the pop up edit box, enter -fno-obj-arc and click Done.

    While you have that panel showing.
    1. Click the plus sign under the Link Binary With Libraries.
    2. In the drop down panel, type the first few letters of System.
    3. Select SystemConfiguration.framework
    4. Click Add.

    In the Reachability.h file add the following line to get rid of some warnings.
    #import <netinet/in.h>

    I've setup an ivar in my app delegate and make calls to that. I've also setup the notification so that I could have a little red light / green light icon that tells me when the connection is on or off.
     
  8. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #8
    That's good to know. So what it is doing is adding a 'Flag' of some kind to the Reachability class that tells the compiler to treat just this one class differently?

    Thanks.
     
  9. xStep, Apr 21, 2012
    Last edited: Apr 21, 2012

    xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #9
    Yes. Also the Analyzer accounts for it too from what I see. OH, and the editor.
     

Share This Page