user1419810 user1419810 - 1 year ago 70
Objective-C Question

Show error message is internet not available

I'm loading a webview and am using SVProgressHUD to display a loading message whilst the page is loaded. Is it possible to show an error message if there isn't an internet connection available, if so how would i do this?

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

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

Answer Source

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

    Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
    if (networkStatus == NotReachable)
        return NO;
        return YES;

How to use:

if([className IsInternet]){
//Load the page
// Show message internet not available
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download