【发布时间】:2011-01-22 20:15:48
【问题描述】:
我已下载苹果可达性(.h+.m)文件并将其添加到我的视图库项目中,并且没有进行任何更改。我还添加了 systemconfiguration.framework。
在我的 viewcontroller.h 文件中,我在“@interface”之前添加了“@class 可达性”,并且还添加了“- (void) checkNetworkStatus:(NSNotification *)notice;”就在“@end”之前。
我已将reachability.h 导入到我的viewcontroller.m 文件中,其余部分如下:
// 检查网络连接 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
[hostReachable startNotifier];
// now patiently wait for the notification
- (void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
self.internetActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
NSLog(@"A gateway to the host server is down.");
self.hostActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"A gateway to the host server is working via WIFI.");
self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"A gateway to the host server is working via WWAN.");
self.hostActive = YES;
break;
}
}
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload
{
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
@end
我收到 2 个警告: -“类'TestViewController'的错误实现”(在我尝试这样做之前有效) -还有,“-'checkNetworkStatus:' 的方法定义:'未找到”
这两个错误是: -“'checkNetworkStatus' 未声明” -和“预期的';'在':'之前"
谁能帮帮我?
编辑:
.h 文件:
>#import <UIKit/UIKit.h>
@class Reachability;
@interface TestViewController : UIViewController {
IBOutlet UIView *landscape;
IBOutlet UIView *portrait;
IBOutlet UIView *portraitupsidedown;
IBOutlet UIWebView *WebView;
IBOutlet UIWebView *WebView2;
IBOutlet UIWebView *WebView3;
IBOutlet UIWebView *WebView4;
Reachability* internetReachable;
Reachability* hostReachable;
}
@property(nonatomic,retain) UIView *landscape;
@property(nonatomic,retain) UIView *portrait;
@property(nonatomic,retain) UIView *portraitupsidedown;
- (void) checkNetworkStatus:(NSNotification *)notice;
@end
【问题讨论】:
标签: objective-c xcode ios ios4