Need Reachability version for ARC in iOS5

2019-03-09 17:05发布

问题:

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?

回答1:

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



回答2:

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.



回答3:

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

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



回答4:

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

https://gist.github.com/1182373



回答5:

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

Here is the link to the sample by Apple



回答6:

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



回答7:

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.



回答8:

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; 
}