在我的啓動畫面中,我訂閱了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