17

我正在尝试在我的项目中使用可达性。我添加了 Reachability.h 和 Reachability.m 文件。但是在构建项目后,xCode 向我显示了奇怪的错误:

Undefined symbols for architecture i386:
"_SCNetworkReachabilityCreateWithName", referenced from:
  +[Reachability reachabilityWithHostname:] in Reachability.o
"_SCNetworkReachabilityCreateWithAddress", referenced from:
  +[Reachability reachabilityWithAddress:] in Reachability.o
"_SCNetworkReachabilitySetCallback", referenced from:
  -[Reachability startNotifier] in Reachability.o
  -[Reachability stopNotifier] in Reachability.o
"_SCError", referenced from:
  -[Reachability startNotifier] in Reachability.o
"_SCErrorString", referenced from:
  -[Reachability startNotifier] in Reachability.o
"_SCNetworkReachabilitySetDispatchQueue", referenced from:
  -[Reachability startNotifier] in Reachability.o
  -[Reachability stopNotifier] in Reachability.o
"_SCNetworkReachabilityGetFlags", referenced from:
  -[Reachability isReachable] in Reachability.o
  -[Reachability isReachableViaWWAN] in Reachability.o
  -[Reachability isReachableViaWiFi] in Reachability.o
  -[Reachability connectionRequired] in Reachability.o
  -[Reachability isConnectionOnDemand] in Reachability.o
  -[Reachability isInterventionRequired] in Reachability.o
  -[Reachability reachabilityFlags] in Reachability.o

我怎么解决这个问题?

4

3 回答 3

42

可能您忘记将 SystemConfiguration.framework 添加到您的项目中。如果您不知道如何添加框架,请查看这个SO question

于 2012-06-13T11:37:50.603 回答
3

添加这些框架.. SystemConfiguration.framework Security.framework CFNetwork.framework

于 2012-06-13T11:42:06.513 回答
2

添加 Reachability .h 和 .m 文件时,我遇到了同样的错误。

解决方案是确保 Reachability .m 与您的其余 .m 文件一起编译。你需要这样做。

  1. 单击项目导航器 - 播放/停止按钮下左上角的文件夹图标。
  2. 选择目标
  3. 单击“构建阶段”。
  4. 单击“+”图标。并将 Reachability.m 文件添加到您的编译源中。
于 2012-11-11T12:22:11.510 回答