Answer the question
In order to leave comments, you need to log in
How to handle an error when the site accessed by the program is unavailable?
I'm working on an iOS program that uses data from a specific site. And it happens that the site is cut off, as if a non-existent domain was introduced. I want to handle this error somehow so that the program does not crash. Suggest something!
I check the connection like this, but for some reason it does not work.
Reachability* appleReachability = [Reachability reachabilityWithHostName: @"www.sitename.ru"];
NetworkStatus status = appleReachability.currentReachabilityStatus;
switch (status) {
case NotReachable:{
self.noConnect = [[UIAlertView alloc] initWithTitle:@"Хост недоступен" message:@"Возможно отсутствует подключение к сети Интернет, проверьте соединение и повторите попытку снова." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[self.noConnect show];
// хост недоступен
}
break;
case ReachableViaWiFi:
[self loadData];
// доступен через WiFi
break;
case ReachableViaWWAN:
[self loadData];
// доступен через 3G или EDGE
break;
}
}
Answer the question
In order to leave comments, you need to log in
Perhaps you forgot to call startNotifier
ie. code should look like this
_hostReachable = [Reachability reachabilityWithHostName: host];
[_hostReachable startNotifier];
-(void) checkNetworkStatus:(NSNotification *)notice
{
//Проверяем есть ли доступ в интернет.
NetworkStatus internetStatus = [_internetReachable currentReachabilityStatus];
if (internetStatus==NotReachable) {
....
}
...
}
And why not make test data on the local machine for development?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question