You will need to detect the network status changes of your device.
This answer(Method 2) will show you step-by-step of how you can do that. The checkNetworkStatus
method will get called every time if the device's is changed from WiFi to 3G, or from WiFi to not being connected to the internet.
To reload your UIWebView when the network status changes. Your checkNetworkStatus
should look something like this:
-(void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
self.internetActive = NO;
//show an alertView saying the device has no internet connection.
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
self.internetActive = YES;
//reload UIWebView
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[self.webView loadRequest:nsrequest];
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
self.internetActive = YES;
//reload UIWebView
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[self.webView loadRequest:nsrequest];
break;
}
}
// anything else
}