32

Using Apple's Reachability code in iOS5 I get a bunch of compilation errors as shown below. Any ideas on what is happening here? I'm using ARC so I have edited the standard code slightly to remove autorelease/retain and the NSAutoReleasePool.

Undefined symbols for architecture armv7:

"_SCNetworkReachabilityCreateWithAddress", referenced from: +[Reachability reachabilityWithAddress:] in Reachability.o

"_SCNetworkReachabilityCreateWithName", referenced from: +[Reachability reachabilityWithHostName:] in Reachability.o

"_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from: -[Reachability stopNotifier] in Reachability.o

"_SCNetworkReachabilityScheduleWithRunLoop", referenced from: -[Reachability startNotifier] in Reachability.o

"_SCNetworkReachabilitySetCallback", referenced from: -[Reachability startNotifier] in Reachability.o

"_SCNetworkReachabilityGetFlags", referenced from: -[Reachability connectionRequired] in Reachability.o -[Reachability currentReachabilityStatus] in Reachability.o

ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone have workable Reachability code for ARC under iOS5?

Philipp Schlösser
  • 5,179
  • 2
  • 38
  • 52
millport
  • 2,411
  • 5
  • 23
  • 19
  • 4
    You can turn off ARC with some files. Look this answer http://stackoverflow.com/questions/6308425/ios-5-best-practice-release-retain/6429909#6429909 – JSanchez Oct 21 '11 at 12:01
  • All these answers, most if not all are perfectly valid but you haven't marked one as correct? – theiOSDude Oct 02 '13 at 11:04

8 Answers8

59

I wrote a clean 'drop in' version of reachability for ARC and iOS5 - you can get it here: https://github.com/tonymillion/Reachability

Tony Million
  • 4,296
  • 24
  • 24
  • Lokoing at your code I see that isReachableViaWWAN returns NO automatically on an iPad. How does this work with a 3g enabled iPad? – Nailer Dec 13 '11 at 11:35
  • 2
    You are incorrect, it will return correctly on the iPad as TARGET_OS_IPHONE is defined when compiling for iPad - it will return NO automatically when compiling for MacOS as it doesn't have the kSCNetworkReachabilityFlagsIsWWAN flag. If you check SCNetworkReachability.h you'll see its wrapped up in the same #if statement. – Tony Million Dec 13 '11 at 15:19
  • My bad. I didn´t know TARGET_OS_IPHONE was defined on iPad. Confusing name and all. Anyway, it worked great! Thanks =) I guess that define is legacy from the pre iOS days. – Nailer Dec 13 '11 at 15:30
  • Works great Tony! The README didn't call out the need to dispatch_async() back to the main thread (though your sample project does). I've taken a common use case and included a gist of it for other readers, full of comments: https://gist.github.com/2568090 – idStar May 01 '12 at 14:01
  • 3
    Hi, your Gist is completely wrong, if you only need to periodically check for connectivity you do not need the notifier code, you can simply test the reachability on an adhoc basis. If you need a notification to know when network connectivity status has changed (for example in an IM client) then you would use the notifier. The code is documented to let the user know that the blocks are not called on the main thread. – Tony Million May 01 '12 at 17:18
  • 1
    For example the following code would suffice [[Reachability reachabilityWithHostname:kRPWebsite_REPSPRO] isReachable]; – Tony Million May 01 '12 at 17:20
44

You don't really need an ARC version of Reachability, just simply disable ARC for reachability file(s)

Disable ARC on MULTIPLE files:

  • Select desired files at Target/Build Phases/Compile Sources in Xcode
  • PRESS ENTER
  • Type -fno-objc-arc
  • Press Enter or Done

You also have a missing framework. Add SystemConfiguration framework.

Tibidabo
  • 21,461
  • 5
  • 90
  • 86
  • Brilliant!!!! Can you help me find out where to learn all of "-fno-objc-arc" this stuff? Does Apple list all of the compiler flags? I think that is something that every advanced programmer should learn! – Albert Renshaw Jul 05 '13 at 20:39
  • @AlbertRenshaw It must be somewhere in the documentation, but it's way much faster to google it. – Tibidabo Jul 09 '13 at 06:13
  • http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html – Albert Renshaw Jul 09 '13 at 14:27
  • ^Very extensive list... However, It didn't list your `-fno-objc-arc` – Albert Renshaw Jul 09 '13 at 14:28
  • I just tried this on my project - and it didn't make any difference. The "Convert to Objective-C ARC" still complains about the same line in the Reachability.m file. – CasaDelGato Oct 07 '13 at 18:31
11

I rearranged them for IOS 5 and arc they are working tested

Please DON'T FORGET TO ADD SystemConfiguration.framework on your project

Rifat Döver
  • 494
  • 4
  • 17
  • Thanks for this comment. I was still getting those symbol reference errors till I added SystemConfiguration.framework. – caleb Apr 26 '12 at 22:36
10

I just found this that might help. Thank the author for this (this is not mine)!

https://gist.github.com/1182373

Peter
  • 101
  • 2
7

Apple's reachability has been updated to version 3 which now supports ARC iOS5+

Here is the link to the sample by Apple

theiOSDude
  • 1,480
  • 2
  • 21
  • 36
3

You need to add the systemConfiguration.framework to make Reachability work.

Marsman
  • 825
  • 1
  • 10
  • 20
2

I know this thread is old, but in case anyone is interested you can solve this by disabling ARC for Reachability.m. Look at this post.

Community
  • 1
  • 1
Kasper Munck
  • 4,173
  • 2
  • 27
  • 50
1

Tony, is your class correctly work even with a non ARC project? I can see lot ok Reachability: dealloc in my consolle, and I don't know if it's normal or not! I use this method to check the connection (is the only place where I user Rechability)

-(BOOL)checkConnection{
    BOOL connessione = FALSE;
    Reachability *wifiResouce       = [[Reachability reachabilityForLocalWiFi] retain];
    Reachability *phoneResouce      = [[Reachability reachabilityForInternetConnection] retain];

    NetworkStatus netStatusWiFi     = [wifiResouce currentReachabilityStatus];
    NetworkStatus netStatusPhone    = [phoneResouce currentReachabilityStatus];
    if(netStatusWiFi == NotReachable){
        if(netStatusPhone == ReachableViaWWAN){
            connessione = TRUE;
        }
    }else if(netStatusWiFi == ReachableViaWiFi){
        connessione = TRUE;
    }
    [phoneResouce release];
    [wifiResouce release];
    return connessione; 
}