标签:
/**
* 检测是否能上网
*
* @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;
}
}
标签:
原文地址:http://www.cnblogs.com/now-or-never/p/5635168.html