//检测网络是否可以使用
+(BOOL)checkNetworkCanUse{
// NSURL *myUrl = [NSURL URLWithString:@"http://139.196.201.235:8006/checknet/checknet.html"];
// NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:myUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:3];
// NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
// NSString* result1 = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
// // NSLog(@"验证是否联网返回的结果是%@",result1);
// if ([result1 isEqualToString:@""]) {
// return NO;
// }else if (result1) {
// return YES;
// }else {
// return NO;
// }
// if ([self CheckCycle] == SUCCESS) {
// return YES;
// }else {
// return NO;
// }
//用苹果官方的检测是不是真正能联网
NSURL *myUrl = [NSURL URLWithString:@"http://captive.apple.com/hotspot-detect.html"];
// NSURLRequest* request = [NSURLRequest requestWithURL:myUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:3];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myUrl];
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString* result1 = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
if ([result1 isEqualToString:@""]) {
return NO;
}else if ([result1 isEqualToString:@"Success"]) {
return YES;
}else {
return NO;
}
}
网友评论