Error With my Implementation of Reachability to Check if Connected to Internet

Discussion in 'iOS Programming' started by gwelmarten, Apr 2, 2012.

  1. gwelmarten macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #1
    Hi
    I'm trying to implement reachability into my iPhone app to allow me to determine if the user has an internet connection. Unfortunately, I am getting two errors whilst trying to build the app. These are the steps I took to implement it:

    I added the SystemConfiguration framework and added Reachability.h/.m to my classes folder.
    I then added this to my viewcontroller.h file for the viewcontroller in which I am detecting an internet connection:
    Code:
    //Class.h
    #import "Reachability.h"
    #import <SystemConfiguration/SystemConfiguration.h>
    
    - (BOOL)connected ;
    Code:
    In my .m file, I use this code as a boolean method, which when run will return if the user has an internet connection:
    - (BOOL)connected 
    {
        Reachability *reachability = [Reachability reachabilityForInternetConnection];  
        NetworkStatus networkStatus = [reachability currentReachabilityStatus]; 
        return !(networkStatus == NotReachable);
    }
    And then when I want to check if I am connected to the internet, I call this:
    Code:
    if(![self connected])
        {
            // not connected    
        } else
        {
            // connected, do some internet stuff 
        }
    Unfortunately, when I build, I get the following two errors:

    Code:
    Ld /Users/Samuel/Library/Developer/Xcode/DerivedData/Funny_Maths-ctillajbcxujxhdywykbwodfufrw/Build/Products/Debug-iphonesimulator/reactionfree.app/reactionfree normal i386
    
        cd "/Users/Samuel/Documents/Projects/Apps/Funny Math Reachability"
    
        setenv MACOSX_DEPLOYMENT_TARGET 10.6
    
        setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/Samuel/Library/Developer/Xcode/DerivedData/Funny_Maths-ctillajbcxujxhdywykbwodfufrw/Build/Products/Debug-iphonesimulator "-L/Users/Samuel/Documents/Projects/Apps/Funny Math Reachability/GoogleAdMobAdsSDKiOS-5.0.5" -F/Users/Samuel/Library/Developer/Xcode/DerivedData/Funny_Maths-ctillajbcxujxhdywykbwodfufrw/Build/Products/Debug-iphonesimulator -filelist "/Users/Samuel/Library/Developer/Xcode/DerivedData/Funny_Maths-ctillajbcxujxhdywykbwodfufrw/Build/Intermediates/Funny Maths.build/Debug-iphonesimulator/Funny Maths.build/Objects-normal/i386/reactionfree.LinkFileList" -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -framework SystemConfiguration -framework QuartzCore -framework iAd -lsqlite3 -lz -framework MapKit -framework CoreLocation -framework AVFoundation -framework AddressBook -framework MessageUI -framework AudioToolbox -framework Foundation -framework UIKit -framework CoreGraphics -lGoogleAdMobAds -o /Users/Samuel/Library/Developer/Xcode/DerivedData/Funny_Maths-ctillajbcxujxhdywykbwodfufrw/Build/Products/Debug-iphonesimulator/reactionfree.app/reactionfree
    
    
    
    Undefined symbols for architecture i386:
    
      [B][I][U]"_OBJC_CLASS_$_Reachability", referenced from:[/U][/I][/B]
    
          objc-class-ref in RssFunViewController.o
    
    ld: symbol(s) not found for architecture i386
    
    clang: error: [B][I][U]linker command failed with exit code 1 (use -v to see invocation)[/U][/I][/B]
    

    where the stuff in bold, underline and italics is the stuff in red in the error log, and hence the name of the bug.

    I've no idea what's going on - something I've done wrong with my frameworks and architecture settings maybe?

    Any help is much appreciated,
    Thanks in advance,
    Sam
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Don't you need alot more frameworks? not sure, but that might be a good start to look at.
    Also for the newer versions of Xcode, you need to import this to supress a warning.

    Code:
    #import <netinet/in.h>
    
     
  3. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    Apparently Reachability.m isn't being compiled. Is it in your project and in your Target? Can you see it being compiled in the build log?
     
  4. gwelmarten thread starter macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #4
    Thanks jnoxx for the import stuff, though I had the same frameworks as Apple in their example project.
    Thanks PhoneyDeveloper - I just hadn't added that reachability.m to the build target - that's a new feature of Xcode isn't it, where it doesn't add it automatically?

    Sam
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Yeah, something funky going on here. Seems Xcode no longer remembers to carry over the "Add to targets" checkbox settings. I thought in the past it would set it to what it was the last time you added some files. I can't seem to get it to stay checked anymore. Xcode bug, perhaps?
     
  6. gwelmarten thread starter macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #6
    Yeah - I've had that bug before - just forgot to check that this time. It is odd of Apple to leave it like that though - it's fairly well documented how annoying it is...
     

Share This Page