0

I'm loading a webview and am using SVProgressHUD to display a loading message whilst the page is loaded.

Here is my code:

- (void)viewDidLoad{
    [super viewDidLoad];
    _infowebView.delegate = self;
    NSURL *url = [NSURL URLWithString:@"http://example.com"];
    [self.infowebView loadRequest:[NSURLRequest requestWithURL:url]];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [SVProgressHUD showWithStatus:@"Loading"];
}

Is it possible to show an error message if there isn't an internet connection available, if so how would i do this?

vaibhav
  • 4,038
  • 1
  • 21
  • 51
user1419810
  • 836
  • 1
  • 16
  • 29
  • duplicate of http://stackoverflow.com/questions/477852/checking-for-internet-connectivity-in-objective-c – PlusInfosys Nov 24 '16 at 05:56
  • you can check internet connectivity before you initiate internet required code, use [readability classes](https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html). – vaibhav Nov 24 '16 at 06:18
  • I simply used this:- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { [SVProgressHUD showInfoWithStatus:@"Internet Connection Unavailable"]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; } Is this bad practice? – user1419810 Nov 24 '16 at 06:25

1 Answers1

0

Before loading the page you can check the internet connection using the reachability class:

+(BOOL)IsInternet
{
    Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
    if (networkStatus == NotReachable)
    {
        return NO;
    }
    else
    {
        return YES;
    }
}

How to use:

if([className IsInternet]){
//Load the page
}else{
// Show message internet not available
}
Saurabh Jain
  • 1,688
  • 14
  • 28