Quote:
Originally Posted by wynodir
If the code in any case connects to a web server to try if there's a connection, why not just do this:
Code:
- (BOOL) connectedToNetwork
{
return ([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.myserver.com/smalltext.txt"]]!=NULL)?YES:NO;
}
This function will return NO if it cannot reach the file. Otherwise, it will return YES. I tried it in flight mode and in 3G mode. It works.
|
i tryed the following code, put my iphone in airplane mode and ran the app. it appears to not work...at all
Code:
- (BOOL) connectedToNetwork {
return ([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.apple.com/"]]!=NULL)?YES:NO;
if (YES) {
}
if (NO) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"no internet connection"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}