2010-05-07 49 views
7

我试图使用苹果发布的可达性项目来检测自己示例中的可达性。我复制了最初始的,但我得到这个故障在链接:从苹果复制了可达性测试,但链接器发生故障

Ld build/switchViews.build/Debug-iphoneos/test.build/Objects-normal/armv6/test normal armv6 
cd /Users/uid04100/Documents/TEST 
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1.3 
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" 
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk -L/Users/uid04100/Documents/TEST/build/Debug-iphoneos -F/Users/uid04100/Documents/TEST/build/Debug-iphoneos -filelist /Users/uid04100/Documents/TEST/build/switchViews.build/Debug-iphoneos/test.build/Objects-normal/armv6/test.LinkFileList -dead_strip -miphoneos-version-min=3.1.3 -framework Foundation -framework UIKit -framework CoreGraphics -o /Users/uid04100/Documents/TEST/build/switchViews.build/Debug-iphoneos/test.build/Objects-normal/armv6/test 

未定义的符号:
“_SCNetworkReachabilitySetCallback”, 从引用: - 在Reachability.o
[可达startNotifer]“ _SCNetworkReachabilityScheduleWithRunLoop “_SCNetworkReachabilityCreateWithAddress”: + [可达性reachabilityWithAddress]在 Reachability.o
, 从引用的” 10从参考: - 在Reachability.o [可达startNotifer]
“_SCNetworkReachabilityGetFlags”, 从引用: - [可达connectionRequired]在Reachability.o - [可达currentReachabilityStatus]在 Reachability.o
“_SCNetworkReachabilityUnscheduleFromRunLoop” , 引用自: - [可达stopNotifer]在Reachability.o
“_SCNetworkReachabilityCreateWithName”,从引用: + [可达性reachabilityWithHostName:]在 Reachability.o
LD:符号(S)没有发现
collect2:LD返回1退出状态

我delegate.h:

#import <UIKit/UIKit.h> 

@class Reachability; 

@interface testAppDelegate : NSObject 
<UIApplicationDelegate> { UIWindow 
*window; UINavigationController *navigationController; 

Reachability* hostReach; 
Reachability* internetReach; 
Reachability* wifiReach; 

} 

@property (nonatomic, retain) IBOutlet 
UIWindow *window; @property 
(nonatomic, retain) IBOutlet 
UINavigationController 
*navigationController; 

@end 

我delegate.m:

#import "testAppDelegate.h" 

#import "SecondViewController.h" 
#import "Reachability.h" 

@implementation testAppDelegate 



@synthesize window; @synthesize 
navigationController; 

- (void) updateInterfaceWithReachability: 
(Reachability*) curReach { 
    if(curReach == hostReach) { 
     BOOL connectionRequired= [curReach connectionRequired]; 


     if(connectionRequired) 
     { //in these brackets schould be some code with sense, if i´m getting it to run 
     } 
     else 
     { 
     } 

    } if(curReach == internetReach) { } if(curReach == wifiReach) { 
} } 

//Called by Reachability whenever 
status changes. 
- (void) reachabilityChanged: (NSNotification*)note { 
Reachability* curReach = [note 
object]; NSParameterAssert([curReach 
isKindOfClass: [Reachability class]]); 
[self 
updateInterfaceWithReachability: 
curReach]; } 


- (void)applicationDidFinishLaunching:(UIApplication 
*)application {  
    // Override point for customization after application launch 
    // Observe the 
kNetworkReachabilityChangedNotification. 
When that notification is posted, the 
    // method "reachabilityChanged" will be called. // 
[[NSNotificationCenter defaultCenter] 
addObserver: self selector: 
@selector(reachabilityChanged:) name: 
kReachabilityChangedNotification 
object: nil]; 

    //Change the host name here to change the server your monitoring 
hostReach = [[Reachability 
reachabilityWithHostName: 
@"www.apple.com"] retain]; [hostReach 
startNotifer]; [self 
updateInterfaceWithReachability: 
hostReach]; 

    internetReach = [[Reachability reachabilityForInternetConnection] 
retain]; [internetReach 
startNotifer]; [self 
updateInterfaceWithReachability: 
internetReach]; 

    wifiReach = [[Reachability reachabilityForLocalWiFi] retain]; 
[wifiReach startNotifer]; [self 
updateInterfaceWithReachability:wifiReach]; 
    [window addSubview:[navigationController 
view]]; 
    [window makeKeyAndVisible]; } 


- (void)dealloc { [navigationController release]; 
    [window release]; 
    [super dealloc]; } 


@end 

回答

18

算了。我只是不知道我必须手动添加systemconfiguration-framework。我认为它会在导入时添加。

+1

您不导入框架;您导入标题。正如您所见,将头文件导入源文件不会将框架添加到项目或目标中。 – 2010-05-08 19:56:21

+5

是的,添加SystemConfiguration.framework将解决问题。 – tszming 2011-01-13 02:41:26