Quote:
Originally Posted by rhuettl
Hi there,
is there a simple piece of code testing if the internet is available on the iPhone - i know the reachability example app but that seems to be a great overhead. So i only like a network test (CFNetwork ?) who can check this - any help available?
Cheers :-)
Ralf
|
Two methods I tried. Reachability is still the best for me. It detect even changes from WifI to 3G to EDGE, etc...
Easier to use method is the UIWebView protocol itself. Hope the code below helps.
#pragma mark UIWebView delegate methods
- (void)webViewDidStartLoad

UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[myActivityIndicatorView startAnimating];
}
- (void)webViewDidFinishLoad

UIWebView *)webView
{
[myActivityIndicatorView stopAnimating];
}
- (void)webView

UIWebView *)webView didFailLoadWithError

NSError *)error
{
int myErrorCode;
[myActivityIndicatorView stopAnimating];
myErrorCode = [error code]; // myErrorCode = -999 if user cancel action, not network problem
if (ckErrorCode != -999)
{
// Your error handling code here
NSLog(@"UIWebView Load Failed-Error");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error!" message:@"Unable to connect to the website." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
}
// #pragma mark UIWebView delegate methods