Objective-C检查网络是否可用的代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

SCNetworkReachabilityFlags flags;
    BOOL receivedFlags;
  
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"google.com" UTF8String]);
    receivedFlags = SCNetworkReachabilityGetFlags(reachability, &flags);
    CFRelease(reachability);
  
    //NSLog(@"idiotic flags %@", receivedFlags);
  
    if (!receivedFlags || (flags == 0))
    {
        return NO;
    } else {
        return YES;
    }