-(BOOL)checkReachability{
CFNetDiagnosticRef dReference;
dReference =CFNetDiagnosticCreateWithURL(NULL,(__bridge CFURLRef)[NSURL URLWithString:@"https://www.baidu.com"]);
CFNetDiagnosticStatus status;
status =CFNetDiagnosticCopyNetworkStatusPassively(dReference,NULL);CFRelease(dReference);if( status == kCFNetDiagnosticConnectionUp ){NSLog(@"连接正常");return YES;}else{NSLog(@"连接失败");return NO;}}
CFNetDiagnosticStatus 枚举
typedefCF_ENUM(int, CFNetDiagnosticStatusValues){/*
* There is no status, but no error has occured
*/
kCFNetDiagnosticNoErr =0,//没有状态返回,也没有报错/*
* An error occured that prevented the call from completing
*/
kCFNetDiagnosticErr =-66560L,//发生问题/*
* The connection appears to be working
*/
kCFNetDiagnosticConnectionUp =-66559L,//连接正常
kCFNetDiagnosticConnectionIndeterminate =-66558L,//不确定的/*
* The connection does not appear to be working
*/
kCFNetDiagnosticConnectionDown =-66557L//连接失败}CF_DEPRECATED(10_4,10_13,2_0,11_0);