iOS 判断手机的网络状况

网上去下载  Reachability的框架,  根据框架  去判断手机的网络状态


-(BOOL)isConnectionAvailable{

    BOOL isExistenceNetwork = YES;

    Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];

    switch ([reach currentReachabilityStatus]) {

        case NotReachable:

            isExistenceNetwork = NO;

            return isExistenceNetwork;

            //NSLog(@"notReachable");

            break;

        case ReachableViaWiFi:

            isExistenceNetwork = YES;

            return isExistenceNetwork;

            

            //NSLog(@"WIFI");

            break;

        case ReachableViaWWAN:

            isExistenceNetwork = YES;

            return isExistenceNetwork;

            

            //NSLog(@"3G");

            break;

    }

    return isExistenceNetwork;

}


    //判断网络状态

    if( ![self isConnectionAvailable]){

        UIAlertView *aler=[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前无网络连接,请检查网络" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        [aler show];

    }



你可能感兴趣的:(iOS 判断手机的网络状况)