在我的启动画面中,我订阅了UIApplicationDidBecomeActiveNotification。检查Internet连接iOS App
- (void)viewDidLoad
{
[super viewDidLoad];
// register notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkInternetConnection:) name:UIApplicationDidBecomeActiveNotification object:nil];
}
-(void) checkInternetConnection:(NSNotification *) notification
{
internetStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
if(internetStatus == NotReachable)
{
[AppHelper showAlert:@"ERROR" message:@"Error downloading data. Please check your network connection and try again." cancelButtonTitle:nil otherButtonTitles:@[@"OK"]];
return;
}
[self viewDidAppear:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if(!(internetStatus == NotReachable))
{
AppDelegate *applicationDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[applicationDelegate performSelector:@selector(showMainMenu) withObject:[NSNumber numberWithBool:YES] afterDelay:3.0];
}
}
的问题是,互联网连接将只在启动屏幕上检查,所以如果我在其他一些画面中,我失去互联网连接那么有没有办法告诉大家,连接已不见了。我怎样才能做出一个好的逻辑来检查客户的互联网连接。
你使用的是webview。 – 2013-05-14 16:47:11
希望这下面的链接是有用的.. [http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk] [1] [1]:http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk – 2013-05-14 16:50:03