【发布时间】:2012-12-25 02:35:15
【问题描述】:
可能重复:
Undefined symbols for architecture armv7: “_SCNetworkReachabilityCreateWithAddress”
我尝试了一些我在这里找到的东西,但都没有奏效。我将 Apple 的 reachability.h 和 .m 文件添加到我的项目中。我正在尝试测试 mogul 服务器的可达性,以下是我在实际程序中使用的代码:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification
object:nil];
reach = [Reachability reachabilityForInternetConnection];
[reach startNotifier];
NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];
if (remoteHostStatus == NotReachable) {
NSLog(@"no");
textTest.text = @"Can't reach it";
}
else if(remoteHostStatus == ReachableViaWiFi || remoteHostStatus == ReachableViaWWAN){
NSLog(@"Yes");
textTest.text = @"Got it";
}
testServer.hidden = YES;
....
-(void)handleNetworkChange:(NSNotification *)notice{
NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];
if (remoteHostStatus == NotReachable) {
NSLog(@"no");
textTest.text = @"Can't get it";
}
else if(remoteHostStatus == ReachableViaWiFi || remoteHostStatus == ReachableViaWWAN){
NSLog(@"Got it");
textTest.text = @"Got it";
}
}
在 .h 文件中:
@property (retain, nonatomic) Reachability *reach;
....
-(void)handleNetworkChange:(NSNotification *)notice;
每次我尝试编译和运行时,都会得到以下结果:
Ld /Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator/newClient.app/newClient normal i386
cd /Volumes/TRAVELDRIVE/Reseaech/ClientSide/newClient
setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -L/Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator -F/Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator -filelist /Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Intermediates/newClient.build/Debug-iphonesimulator/newClient.build/Objects-normal/i386/newClient.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.0 -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/ConorMccallion/Library/Developer/Xcode/DerivedData/newClient-aunayptutxnlhjeoflldefcmybpk/Build/Products/Debug-iphonesimulator/newClient.app/newClient
Undefined symbols for architecture i386:
"_SCNetworkReachabilityCreateWithAddress", referenced from:
+[Reachability reachabilityWithAddress:] in ViewController.o
+[Reachability reachabilityWithAddress:] in Reachability.o
"_SCNetworkReachabilityCreateWithName", referenced from:
+[Reachability reachabilityWithHostName:] in ViewController.o
+[Reachability reachabilityWithHostName:] in Reachability.o
"_SCNetworkReachabilityGetFlags", referenced from:
-[Reachability connectionRequired] in ViewController.o
-[Reachability currentReachabilityStatus] in ViewController.o
-[Reachability connectionRequired] in Reachability.o
-[Reachability currentReachabilityStatus] in Reachability.o
"_SCNetworkReachabilityScheduleWithRunLoop", referenced from:
-[Reachability startNotifier] in ViewController.o
-[Reachability startNotifier] in Reachability.o
"_SCNetworkReachabilitySetCallback", referenced from:
-[Reachability startNotifier] in ViewController.o
-[Reachability startNotifier] in Reachability.o
"_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from:
-[Reachability stopNotifier] in ViewController.o
-[Reachability stopNotifier] in Reachability.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这可能是显而易见的,因此我们将不胜感激。谢谢
【问题讨论】:
-
这不是完全重复的。另一个问题只回答了问题的第二部分。第一部分“如何检查服务器的可达性”在其他问题中不存在。
-
@ACB 你是对的,我会投票重新开放,但应该说在一篇文章中结合两个完全不同的问题被认为是不好的做法,有充分的理由......
-
@jogojapan,是的,这是真的。他应该在谷歌上搜索第二个问题并且会得到它。但是其他问题中提供的解决方案可能对他的情况没有帮助。这可能是一个问题,因为没有为他添加框架,其他问题是基于它已经添加的假设。所以有可能它甚至可能对他根本没有帮助。
标签: iphone objective-c ios xcode reachability