Need Reachability version for ARC in iOS5
Asked Answered
T

8

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?

Tomkins answered 17/10, 2011 at 16:56 Comment(2)
You can turn off ARC with some files. Look this answer #6308925Valerle
All these answers, most if not all are perfectly valid but you haven't marked one as correct?Evidentiary
O
59

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

Operant answered 15/11, 2011 at 14:1 Comment(6)
Lokoing at your code I see that isReachableViaWWAN returns NO automatically on an iPad. How does this work with a 3g enabled iPad?Putput
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.Operant
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.Putput
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: gist.github.com/2568090Ose
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.Operant
For example the following code would suffice [[Reachability reachabilityWithHostname:kRPWebsite_REPSPRO] isReachable];Operant
S
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.

Shire answered 3/4, 2012 at 23:23 Comment(5)
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!Chiron
@AlbertRenshaw It must be somewhere in the documentation, but it's way much faster to google it.Shire
developer.apple.com/library/mac/#documentation/DeveloperTools/…Chiron
^Very extensive list... However, It didn't list your -fno-objc-arcChiron
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.Hinkle
K
11

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

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

Kelby answered 31/12, 2011 at 22:13 Comment(1)
Thanks for this comment. I was still getting those symbol reference errors till I added SystemConfiguration.framework.Bagworm
M
10

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

https://gist.github.com/1182373

Mizuki answered 25/10, 2011 at 19:35 Comment(0)
E
7

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

Here is the link to the sample by Apple

Evidentiary answered 2/10, 2013 at 11:3 Comment(0)
E
3

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

Ernestinaernestine answered 18/2, 2012 at 1:22 Comment(0)
S
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.

Suprarenal answered 18/3, 2012 at 15:35 Comment(0)
D
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; 
}
Disturb answered 2/5, 2012 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.