开发者

Unexpected result when checking network reachability

In my app I implemented the code for network reachability. This is my code.

-(void)viewDidLoad {
// Test for internet.
gotInternet = [self checkInternet];
if (gotInternet == NO) {
    // No Internet.
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Connection Error" message:@"The internet is down" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];

}
else {
    NSLog(@"I do have internet");
}

}


-(BOOL)checkInternet {
//Test for Internet Connection
NSLog开发者_如何学C(@"——–");
NSLog(@"Testing Internet Connectivity");
Reachability *r = [Reachability reachabilityWithHostName:@"https://mobile.areafinancial.com/cutechservice/cutechwebservice.asmx"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
BOOL internet;
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
    internet = NO;
} else {
    internet = YES;
}
return internet;
}

This code returns me gotInternet = NO; Actually WiFi is enabled. What am i doing wrong?

Thank you in advance.


Your problem is you are testing a FULL URL not a HOST NAME.....

    Reachability *r = [Reachability reachabilityWithHostName:@"mobile.areafinancial.com"];
    NetworkStatus internetStatus = [r currentReachabilityStatus];


try this I have modified your code

-(void)viewDidLoad {
// Test for internet.
//gotInternet = [self checkInternet];
if (![self checkInternet]) {
    // No Internet.
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Connection Error" message:@"The internet is down" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];

}
else {
    NSLog(@"I do have internet");
}

}


-(BOOL)checkInternet {
//Test for Internet Connection
NSLog(@"——–");
NSLog(@"Testing Internet Connectivity");
Reachability *r = [Reachability reachabilityWithHostName:@"https://mobile.areafinancial.com/cutechservice/cutechwebservice.asmx"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
BOOL internet;
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
    return NO;
} else {
    return YES;
}
//return internet;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜