获取手机的网络类型

 

 

 

 

#pragma mark - 获取手机的网络类型
- (NSString *)getNetconnType{
    
    NSString *netconnType = @"";
    
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
    
    switch ([reach currentReachabilityStatus]) {
            
        case ReachableViaWiFi:// Wifi
        {
            netconnType = @"WIFI";
        }
            break;
            
        case ReachableViaWWAN:// 手机自带网络
        {
            // 获取手机网络类型
            CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
            CTCarrier *carrier = [info subscriberCellularProvider];
            NSString *name = [carrier carrierName];
            if ([name isEqualToString:@"中国移动"]) {
                netconnType = @"MOBILE";
            }else if ([name isEqualToString:@"中国电信"]){
                netconnType = @"TELECOM";
            }else if ([name isEqualToString:@"中国联通"]){
                netconnType = @"UNICOM";
            }
        }
            break;
            
        default:
            break;
    }
    
    return netconnType;
}

 

posted @ 2019-07-29 11:06  OIMMZC  阅读(139)  评论(0编辑  收藏  举报