IT虾米网

iOS检查网络是否可用的代码

sanshao 2018年06月24日 手机开发 1069 0
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; 
    }

评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!