0

我正在尝试使用苹果示例可达性代码以及下面的代码来检测网络连接。

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

我还添加了系统配置。框架添加到我的项目并将-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)

任何帮助将不胜感激

4

1 回答 1

0

确保 Reachability.m 在 Build Phases 下的 Compile Sources 列表中,然后再次运行。还要确保 Reachability 类不是#importing 本身,而是#importing 其头文件。我还将检查您的 Reachability 类是否实际上是#importing SystemConfiguration 框架,因为您的所有错误都基于其中找到的方法。

于 2012-05-04T04:50:48.393 回答