M
M
MagoVinch2014-03-15 22:54:30
Objective-C
MagoVinch, 2014-03-15 22:54:30

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

[[+comments_count]] answer(s)
A
An, 2014-03-16
@MagoVinch

Perhaps you forgot to call startNotifier
ie. code should look like this

_hostReachable = [Reachability reachabilityWithHostName: host];
 [_hostReachable startNotifier];

Well, plus everything, he throws the kReachabilityChangedNotification notification there
which should be guided in some way
-(void) checkNetworkStatus:(NSNotification *)notice
{
    //Проверяем есть ли доступ в интернет.
    NetworkStatus internetStatus = [_internetReachable currentReachabilityStatus];
    if (internetStatus==NotReachable) {
       ....
    }
    ...
 }

K
Konstantin Dovnar, 2014-03-15
@SolidlSnake

And why not make test data on the local machine for development?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question