在ios上检查网络类型的可达性错误

时间:2012-05-04 04:38:26

标签: iphone ios reachability

我正在尝试使用苹果样本可访问性代码以及下面的代码来检测网络连接。

Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];

    NetworkStatus status = [reachability currentReachabilityStatus];

    if(status == NotReachable) 
    {
        //No internet
    }
    else if (status == ReachableViaWiFi)
    {
        //WiFi
    }
    else if (status == ReachableViaWWAN) 
    {
        //3G
    }

    [reachability stopNotifier];
}

我还添加了systemConfiguration。我的项目的框架,并将 -fno-objc-arc 添加到编译器源,以便与ARC兼容的覆盖率文件,我当前如何得到此错误......

 "_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)

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

确保Reachability.m位于Build Phases下的Compile Sources列表中并再次运行。还要确保Reachability类不是#importing本身,并且#importing其头文件。我还会检查你的Reachability类实际上是#importing SystemConfiguration框架,因为你的所有错误都是基于它中的方法。