我尝试使用苹果发布的可达性项目来检测自己示例中的可达性。我复制了最多的初始化,但我在链接器中遇到了这个失败:
我的代表.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
我的代表.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
最佳答案
忘了它。我只是不知道我必须手动添加systemconfiguration-framework。我以为它将在导入时添加。
关于iphone - 从苹果复制了可达性测试,但链接器失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2788354/