可能重複的可達性:
Undefined symbols for architecture armv7: 「_SCNetworkReachabilityCreateWithAddress」如何檢查服務器的
我試了幾件事情,我發現就在這裏,並沒有工作過。我將Apple的reachability.h和.m文件添加到我的項目中。我想測試大亨服務器的可達性,下面是我在我的實際程序中使用的代碼:
[[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)
這也可能是一些顯而易見的,所以答案將不勝感激。謝謝
這不完全相同。只有問題的第二部分由另一個問題回答。其他問題中沒有「如何檢查服務器的可達性」的第一部分。 – iDev
@ACB你是對的,我會投票重新開放,但應該說,在一篇文章中結合兩個相當不同的問題被認爲是不好的做法,有充分的理由...... – jogojapan
@jogojapan,是的,這是真的。他應該做一個谷歌搜索第二個問題,並會得到它。但在其他問題中提供的解決方案可能無助於他的情況。這可能是一個問題,因爲沒有爲他添加框架,而其他問題是基於已經添加的假設。所以有可能它甚至可能根本沒有幫助他。 – iDev