/** * 检测是否能上网 * * @return YES说明网络已经连接;NO说明没有网络连接 */- (BOOL) isConnectionAvailable{ SCNetworkReachabilityFlags flags; BOOL receivedFlags; SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"www.baidu.com" UTF8String]); receivedFlags = SCNetworkReachabilityGetFlags(reachability, &flags); CFRelease(reachability); if (!receivedFlags || (flags == 0) ) { return FALSE; } else { return TRUE; }}
时间: 2024-09-28 18:36:26