4

Possible Duplicate:
Undefined symbols for architecture armv7: “_SCNetworkReachabilityCreateWithAddress”

I tried a couple of things I found on here, and none have worked. I added the reachability.h and .m files from Apple to my project. I'm trying to test the reachability of a mogul server, and the following is the code I used within my actual program:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification
object:nil];

reach = [Reachability reachabilityForInternetConnection];
[reach startNotifier];

NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];

if (remoteHostStatus == NotReachable) {
    NSLog(@"no");
    textTest.text = @"Can't reach it";
}
else if(remoteHostStatus == ReachableViaWiFi || remoteHostStatus == ReachableViaWWAN){
    NSLog(@"Yes");
    textTest.text = @"Got it";
}
testServer.hidden = YES;

....

-(void)handleNetworkChange:(NSNotification *)notice{
    NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];

    if (remoteHostStatus == NotReachable) {
        NSLog(@"no");
        textTest.text = @"Can't get it";
    }
    else if(remoteHostStatus == ReachableViaWiFi || remoteHostStatus == ReachableViaWWAN){
       NSLog(@"Got it");
       textTest.text = @"Got it";
    }
}

and in the .h file:

@property (retain, nonatomic) Reachability *reach;

....

-(void)handleNetworkChange:(NSNotification *)notice;

Every time I try to compile and run this is what I get:

Ld /Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator/newClient.app/newClient normal i386
    cd /Volumes/TRAVELDRIVE/Reseaech/ClientSide/newClient
    setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
    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/iPhoneSimulator6.0.sdk -L/Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator -F/Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator -filelist /Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Intermediates/newClient.build/Debug-iphonesimulator/newClient.build/Objects-normal/i386/newClient.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.0 -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator/newClient.app/newClient

Undefined symbols for architecture i386:
  "_SCNetworkReachabilityCreateWithAddress", referenced from:
      +[Reachability reachabilityWithAddress:] in ViewController.o
      +[Reachability reachabilityWithAddress:] in Reachability.o
  "_SCNetworkReachabilityCreateWithName", referenced from:
      +[Reachability reachabilityWithHostName:] in ViewController.o
      +[Reachability reachabilityWithHostName:] in Reachability.o
  "_SCNetworkReachabilityGetFlags", referenced from:
      -[Reachability connectionRequired] in ViewController.o
      -[Reachability currentReachabilityStatus] in ViewController.o
      -[Reachability connectionRequired] in Reachability.o
      -[Reachability currentReachabilityStatus] in Reachability.o
  "_SCNetworkReachabilityScheduleWithRunLoop", referenced from:
      -[Reachability startNotifier] in ViewController.o
      -[Reachability startNotifier] in Reachability.o
  "_SCNetworkReachabilitySetCallback", referenced from:
      -[Reachability startNotifier] in ViewController.o
      -[Reachability startNotifier] in Reachability.o
  "_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from:
      -[Reachability stopNotifier] in ViewController.o
      -[Reachability stopNotifier] in Reachability.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It's probably something obvious, so an answer would be greatly appreciated. Thank you

Community
  • 1
  • 1
user1927534
  • 51
  • 1
  • 6
  • This is not an exact duplicate. Only the second part of the question is answered by the other question. First part where "how to check reachability of server" is not there in other question. – iDev Dec 28 '12 at 01:43
  • @ACB You are right, and I'll vote to reopen, but it should be said that combining two rather different questions in one post is considered bad practice for good reasons... – jogojapan Dec 28 '12 at 02:00
  • @jogojapan, Yes that is true. He should have done a google search for second question and would have got it. But the solution provided in other question may not help him in his case. It could be an issue because of not adding the framework for him and other question is based on the assumption that it is already added. So there is a chance that it may not even help him at all. – iDev Dec 28 '12 at 02:03

2 Answers2

3

If you want to check the reachability of a particular host, you can use the following code,

Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];

Here you can pass your server name as the host name to check the reachability. It should work. Check the apple documentation for more details.

For the error message you are getting, try adding SystemConfiguration.framework to the project. If that doesn't help, check this Undefined symbols for architecture armv7: "_SCNetworkReachabilityCreateWithAddress".

Community
  • 1
  • 1
iDev
  • 23,310
  • 7
  • 60
  • 85
  • Possibly an ill-considered question: where would I obtain the SystemConfiguration.framework, or is it already on XCode, but not in the way I seem to be expecting? – user1927534 Dec 28 '12 at 01:31
  • 1
    @user1927534, Check this question. Follow the same steps in answer and add this framework instead of the one mentioned there. http://stackoverflow.com/questions/3352664/how-to-add-existing-frameworks-in-xcode-4. Also check this blog http://blog.thinketg.com/blog/david-brainer-banker/xcode-4-tips-adding-frameworks-to-your-project. – iDev Dec 28 '12 at 01:38
0

on didFinishLaunchingWithOptions method put:

self.internetReach= [Reachability reachabilityWithHostName:@"your host name e.g.www.apple.com"];

[internetReach startNotifier];


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];


[self performSelector:@selector(reachabilityChanged:) withObject:[NSNotification notificationWithName:kReachabilityChangedNotification object:internetReach]];

this will call below method

- (void)reachabilityChanged:(NSNotification*)note

{

Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);

if(curReach == self.internetReach)
{
    NetworkStatus netStatus = [curReach currentReachabilityStatus];
    switch (netStatus)
    {
        case ReachableViaWiFi:
        {            
            isInternetConnectionAvilable=YES;
            if(isNetworkNotifierCalledOnce)
            {
                UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Message!" message:@"Internet Available Now" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
                [alert release];
            }
            break;
        }

        case NotReachable:
        {     

            isInternetConnectionAvilable=NO;

            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Message!" message:@"No Internet Connectivity" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alert show];

            [alert release];

            break;
        }
    }

}

isNetworkNotifierCalledOnce=YES;

}

M.B
  • 885
  • 2
  • 15
  • 31