//
//  IPhoneDeviceManager.m
//  VclustersGemini
//
//  Created by APPLE on 2019/6/14.
//  Copyright © 2019 APPLE. All rights reserved.
//

#import "iPhone.h"
#import <sys/utsname.h>
#import <ifaddrs.h>
#import <arpa/inet.h>

/* 运营商 首先需要引入以下两个系统类：*/
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

@implementation iPhone

static iPhone *shareInstance = nil;
+ (iPhone *)shareInstance
{
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        shareInstance = [[iPhone alloc]init];
    });
    
    return shareInstance;
}

#pragma mark 手机相关参数
+ (NSString*)phoneDeviceIPAddress
{
    NSString *address = @"error";
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    // 检索当前接口,在成功时,返回0
    success = getifaddrs(&interfaces);
    if (success == 0) {
        // 循环链表的接口
        temp_addr = interfaces;
        while(temp_addr != NULL) {
            if(temp_addr->ifa_addr->sa_family == AF_INET) {
                // 检查接口是否en0 wifi连接在iPhone上
                if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
                    // 得到NSString从C字符串
                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
                }
            }
            temp_addr = temp_addr->ifa_next;
        }
    }
    // 释放内存
    freeifaddrs(interfaces);
    return address;
}

+ (NSString*)phoneDeviceUuid
{
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}

+ (NSString*)phoneDeviceType
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    if ([deviceModel isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone3,2"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone3,3"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([deviceModel isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([deviceModel isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
    if ([deviceModel isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
    if ([deviceModel isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([deviceModel isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    if ([deviceModel isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([deviceModel isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    if ([deviceModel isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
    // 日行两款手机型号均为日本独占，可能使用索尼FeliCa支付方案而不是苹果支付
    if ([deviceModel isEqualToString:@"iPhone9,1"])    return @"国行、日版、港行iPhone 7";
    if ([deviceModel isEqualToString:@"iPhone9,2"])    return @"港行、国行iPhone 7 Plus";
    if ([deviceModel isEqualToString:@"iPhone9,3"])    return @"美版、台版iPhone 7";
    if ([deviceModel isEqualToString:@"iPhone9,4"])    return @"美版、台版iPhone 7 Plus";
    if ([deviceModel isEqualToString:@"iPhone10,1"])   return @"iPhone_8";
    if ([deviceModel isEqualToString:@"iPhone10,4"])   return @"iPhone_8";
    if ([deviceModel isEqualToString:@"iPhone10,2"])   return @"iPhone_8_Plus";
    if ([deviceModel isEqualToString:@"iPhone10,5"])   return @"iPhone_8_Plus";
    if ([deviceModel isEqualToString:@"iPhone10,3"])   return @"iPhone_X";
    if ([deviceModel isEqualToString:@"iPhone10,6"])   return @"iPhone_X";
    if ([deviceModel isEqualToString:@"iPhone11,2"])   return @"iPhone XS";
    if ([deviceModel isEqualToString:@"iPhone11,4"])   return @"iPhone XS Max";
    if ([deviceModel isEqualToString:@"iPhone11,6"])   return @"iPhone XS Max";
    if ([deviceModel isEqualToString:@"iPhone11,8"])   return @"iPhone XR";
    if ([deviceModel isEqualToString:@"iPhone12,1"])   return @"iPhone 11";
    if ([deviceModel isEqualToString:@"iPhone12,3"])   return @"iPhone 11 Pro";
    if ([deviceModel isEqualToString:@"iPhone12,5"])   return @"iPhone 11 Pro Max";
    if ([deviceModel isEqualToString:@"iPhone12,8"])   return @"iPhone SE2";
    if ([deviceModel isEqualToString:@"iPhone13,1"])   return @"iPhone 12 mini";
    if ([deviceModel isEqualToString:@"iPhone13,2"])   return @"iPhone 12";
    if ([deviceModel isEqualToString:@"iPhone13,3"])   return @"iPhone 12  Pro";
    if ([deviceModel isEqualToString:@"iPhone13,4"])   return @"iPhone 12  Pro Max";
    if ([deviceModel isEqualToString:@"iPhone14,4"])   return @"iPhone 13 mini";
    if ([deviceModel isEqualToString:@"iPhone14,5"])   return @"iPhone 13";
    if ([deviceModel isEqualToString:@"iPhone14,2"])   return @"iPhone 13 Pro";
    if ([deviceModel isEqualToString:@"iPhone14,3"])   return @"iPhone 13 Pro Max";
    
    // iPod
    if ([deviceModel isEqualToString:@"iPod1,1"])  return @"iPod Touch 1";
    if ([deviceModel isEqualToString:@"iPod2,1"])  return @"iPod Touch 2";
    if ([deviceModel isEqualToString:@"iPod3,1"])  return @"iPod Touch 3";
    if ([deviceModel isEqualToString:@"iPod4,1"])  return @"iPod Touch 4";
    if ([deviceModel isEqualToString:@"iPod5,1"])  return @"iPod Touch 5";
    if ([deviceModel isEqualToString:@"iPod7,1"])  return @"iPod Touch 6";
    if ([deviceModel isEqualToString:@"iPod9,1"])  return @"iPod Touch 7";
    
    // iPad
    if ([deviceModel isEqualToString:@"iPad1,1"])  return @"iPad 1";
    if ([deviceModel isEqualToString:@"iPad2,1"])  return @"iPad 2";
    if ([deviceModel isEqualToString:@"iPad2,2"]) return @"iPad 2";
    if ([deviceModel isEqualToString:@"iPad2,3"])  return @"iPad 2";
    if ([deviceModel isEqualToString:@"iPad2,4"])  return @"iPad 2";
    if ([deviceModel isEqualToString:@"iPad2,5"])  return @"iPad Mini 1";
    if ([deviceModel isEqualToString:@"iPad2,6"])  return @"iPad Mini 1";
    if ([deviceModel isEqualToString:@"iPad2,7"])  return @"iPad Mini 1";
    if ([deviceModel isEqualToString:@"iPad3,1"])  return @"iPad 3";
    if ([deviceModel isEqualToString:@"iPad3,2"])  return @"iPad 3";
    if ([deviceModel isEqualToString:@"iPad3,3"])  return @"iPad 3";
    if ([deviceModel isEqualToString:@"iPad3,4"])  return @"iPad 4";
    if ([deviceModel isEqualToString:@"iPad3,5"])  return @"iPad 4";
    if ([deviceModel isEqualToString:@"iPad3,6"])  return @"iPad 4";
    if ([deviceModel isEqualToString:@"iPad4,1"])  return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad4,2"])  return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad4,3"])  return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad4,4"])  return @"iPad mini 2";
    if ([deviceModel isEqualToString:@"iPad4,5"])  return @"iPad mini 2";
    if ([deviceModel isEqualToString:@"iPad4,6"])  return @"iPad mini 2";
    if ([deviceModel isEqualToString:@"iPad4,7"])  return @"iPad mini 3";
    if ([deviceModel isEqualToString:@"iPad4,8"])  return @"iPad mini 3";
    if ([deviceModel isEqualToString:@"iPad4,9"])  return @"iPad mini 3";

    if ([deviceModel isEqualToString:@"iPad5,1"])  return @"iPad mini 4";
    if ([deviceModel isEqualToString:@"iPad5,2"])  return @"iPad mini 4";
    if ([deviceModel isEqualToString:@"iPad5,3"])  return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"iPad5,4"])  return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"iPad6,3"])  return @"iPad Pro (9.7-inch)";
    if ([deviceModel isEqualToString:@"iPad6,4"])  return @"iPad Pro (9.7-inch)";
    if ([deviceModel isEqualToString:@"iPad6,7"])  return @"iPad Pro (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad6,8"])  return @"iPad Pro (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad6,11"])  return @"iPad 5";
    if ([deviceModel isEqualToString:@"iPad6,12"])  return @"iPad 5";

    if ([deviceModel isEqualToString:@"iPad7,1"])  return @"iPad Pro 2(12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad7,2"])  return @"iPad Pro 2(12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad7,3"])  return @"iPad Pro (10.5-inch)";
    if ([deviceModel isEqualToString:@"iPad7,4"])  return @"iPad Pro (10.5-inch)";
    if ([deviceModel isEqualToString:@"iPad7,5"])  return @"iPad 6";
    if ([deviceModel isEqualToString:@"iPad7,6"])  return @"iPad 6";
    if ([deviceModel isEqualToString:@"iPad7,11"])  return @"iPad 7";
    if ([deviceModel isEqualToString:@"iPad7,12"])  return @"iPad 7";
    if ([deviceModel isEqualToString:@"iPad8,1"])  return @"iPad Pro (11-inch)";
    if ([deviceModel isEqualToString:@"iPad8,2"])  return @"iPad Pro (11-inch)";
    if ([deviceModel isEqualToString:@"iPad8,3"])  return @"iPad Pro (11-inch)";
    if ([deviceModel isEqualToString:@"iPad8,4"])  return @"iPad Pro (11-inch)";
    if ([deviceModel isEqualToString:@"iPad8,5"])  return @"iPad Pro 3 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad8,6"])  return @"iPad Pro 3 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad8,7"])  return @"iPad Pro 3 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad8,8"])  return @"iPad Pro 3 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad8,9"])  return @"iPad Pro 2 (11-inch)";
    if ([deviceModel isEqualToString:@"iPad8,10"])  return @"iPad Pro 2 (11-inch)";
    if ([deviceModel isEqualToString:@"iPad8,11"])  return @"iPad Pro 4 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad8,12"])  return @"iPad Pro 4 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad11,1"])  return @"iPad mini 5";
    if ([deviceModel isEqualToString:@"iPad11,2"])  return @"iPad mini 5";
    if ([deviceModel isEqualToString:@"iPad11,3"])  return @"iPad Air 3";
    if ([deviceModel isEqualToString:@"iPad11,4"])  return @"iPad Air 3";
    if ([deviceModel isEqualToString:@"iPad11,6"])  return @"iPad 8";
    if ([deviceModel isEqualToString:@"iPad11,7"])  return @"iPad 8";
    if ([deviceModel isEqualToString:@"iPad12,1"])  return @"iPad 9";
    if ([deviceModel isEqualToString:@"iPad12,2"])  return @"iPad 9";
    if ([deviceModel isEqualToString:@"iPad13,1"])  return @"iPad Air 4";
    if ([deviceModel isEqualToString:@"iPad13,2"])  return @"iPad Air 4";
    if ([deviceModel isEqualToString:@"iPad13,4"])  return @"iPad Pro 4 (11-inch)";
    if ([deviceModel isEqualToString:@"iPad13,5"])  return @"iPad Pro 4 (11-inch)";
    if ([deviceModel isEqualToString:@"iPad13,6"])  return @"iPad Pro 4 (11-inch)";
    if ([deviceModel isEqualToString:@"iPad13,7"])  return @"iPad Pro 4 (11-inch)";
    if ([deviceModel isEqualToString:@"iPad13,8"])  return @"iPad Pro 5 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad13,9"])  return @"iPad Pro 5 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad13,10"])  return @"iPad Pro 5 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad13,11"])  return @"iPad Pro 5 (12.9-inch)";
    if ([deviceModel isEqualToString:@"iPad14,1"])  return @"iPad mini 6";
    if ([deviceModel isEqualToString:@"iPad14,2"])  return @"iPad mini 6";
    
    if ([deviceModel isEqualToString:@"AppleTV2,1"])   return @"Apple TV 2";
    if ([deviceModel isEqualToString:@"AppleTV3,1"])   return @"Apple TV 3";
    if ([deviceModel isEqualToString:@"AppleTV3,2"])   return @"Apple TV 3";
    if ([deviceModel isEqualToString:@"AppleTV5,3"])   return @"Apple TV 4";
    
    if ([deviceModel isEqualToString:@"i386"])         return @"Simulator";
    if ([deviceModel isEqualToString:@"x86_64"])       return @"Simulator";
    
    return deviceModel;
}

+ (NSString*)appVersion
{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
    NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    
    return appVersion;
}

+ (NSString*)phoneVersion
{
    NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
    
    return phoneVersion;
}

+ (NSString*)appBundleName
{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
    //NSString *appVersion = [infoDic objectForKey:@"CFBundleName"];
    NSString *appVersion = [infoDic objectForKey:@"CFBundleDisplayName"];
    
    return appVersion;
}

+ (NSString *)resolution
{
    CGRect  rect   = [[UIScreen mainScreen] bounds];
    CGSize  size   = rect.size;
    CGFloat width  = size.width;
    CGFloat height = size.height;
    NSLog(@"print %f,%f", width, height);
    //分辨率
    CGFloat scale_screen = [UIScreen mainScreen].scale;
    return [NSString stringWithFormat:@"%d*%d", (int)(width * scale_screen), (int)(height * scale_screen)];
}

#pragma mark 验证邮箱格式
+ (BOOL)validateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    
    return [emailTest evaluateWithObject:email];
}

#pragma mark 验证手机号码是否有效
+ (BOOL)isVaildPhoneNo:(NSString *)mobileNum
{
    if (mobileNum.length != 11)
    {
        return NO;
    }
    
    NSString *NEWSTAND = @"^1([3-9])([0-9])\\d{8}$";
    
    /**
     * 手机号码:
     * 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[6, 7, 8], 18[0-9], 170[0-9]
     * 移动号段: 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705
     * 联通号段: 130,131,132,155,156,185,186,145,176,1709
     * 电信号段: 133,153,180,181,189,177,1700
     */
    NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";

    /**
     * 中国移动：China Mobile
     * 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,148,178,1705,172,198
     */
    NSString *CM = @"(^1(3[4-9]|4[78]|5[0-27-9]|7[28]|8[2-478]|9[8])\\d{8}$)|(^1705\\d{7}$)";
    /**
     * 中国联通：China Unicom
     * 130,131,132,155,156,185,186,145,146,176,1709,166,171,175
     */
    NSString *CU = @"(^1(3[0-2]|4[56]|5[56]|6[6]|7[156]|8[56])\\d{8}$)|(^1709\\d{7}$)";
    /**
     * 中国电信：China Telecom
     * 133,153,180,181,189,177,1700,199.170.173,174,177
     */
    NSString *CT = @"(^1(49|99|33|53|77|70|7[34]|8[019])\\d{8}$)|(^1700\\d{7}$)";
    
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    NSPredicate *regextestNe = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", NEWSTAND];
    
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestcm evaluateWithObject:mobileNum] == YES)
        || ([regextestct evaluateWithObject:mobileNum] == YES)
        || ([regextestcu evaluateWithObject:mobileNum] == YES)
        || ([regextestNe evaluateWithObject:mobileNum] == YES))
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

#pragma mark 验证身份证
/**验证身份证*/
//必须满足以下规则
//1. 长度必须是18位，前17位必须是数字，第十八位可以是数字或X
//2. 前两位必须是以下情形中的一种：11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91
//3. 第7到第14位出生年月日。第7到第10位为出生年份；11到12位表示月份，范围为01-12；13到14位为合法的日期
//4. 第17位表示性别，双数表示女，单数表示男
//5. 第18位为前17位的校验位
//算法如下：
//（1）校验和 = (n1 + n11) * 7 + (n2 + n12) * 9 + (n3 + n13) * 10 + (n4 + n14) * 5 + (n5 + n15) * 8 + (n6 + n16) * 4 + (n7 + n17) * 2 + n8 + n9 * 6 + n10 * 3，其中n数值，表示第几位的数字
//（2）余数 ＝ 校验和 % 11
//（3）如果余数为0，校验位应为1，余数为1到10校验位应为字符串“0X98765432”(不包括分号)的第余数位的值（比如余数等于3，校验位应为9）
//6. 出生年份的前两位必须是19或20
+ (BOOL)verifyIDCardNumber:(NSString *)value
{
    value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([value length] != 18) {
        return NO;
    }
    NSString *mmdd = @"(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8])))";
    NSString *leapMmdd = @"0229";
    NSString *year = @"(19|20)[0-9]{2}";
    NSString *leapYear = @"(19|20)(0[48]|[2468][048]|[13579][26])";
    NSString *yearMmdd = [NSString stringWithFormat:@"%@%@", year, mmdd];
    NSString *leapyearMmdd = [NSString stringWithFormat:@"%@%@", leapYear, leapMmdd];
    NSString *yyyyMmdd = [NSString stringWithFormat:@"((%@)|(%@)|(%@))", yearMmdd, leapyearMmdd, @"20000229"];
    NSString *area = @"(1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|82|[7-9]1)[0-9]{4}";
    NSString *regex = [NSString stringWithFormat:@"%@%@%@", area, yyyyMmdd  , @"[0-9]{3}[0-9Xx]"];
    
    NSPredicate *regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    if (![regexTest evaluateWithObject:value]) {
        return NO;
    }
    int summary = ([value substringWithRange:NSMakeRange(0,1)].intValue + [value substringWithRange:NSMakeRange(10,1)].intValue) *7
            + ([value substringWithRange:NSMakeRange(1,1)].intValue + [value substringWithRange:NSMakeRange(11,1)].intValue) *9
            + ([value substringWithRange:NSMakeRange(2,1)].intValue + [value substringWithRange:NSMakeRange(12,1)].intValue) *10
            + ([value substringWithRange:NSMakeRange(3,1)].intValue + [value substringWithRange:NSMakeRange(13,1)].intValue) *5
            + ([value substringWithRange:NSMakeRange(4,1)].intValue + [value substringWithRange:NSMakeRange(14,1)].intValue) *8
            + ([value substringWithRange:NSMakeRange(5,1)].intValue + [value substringWithRange:NSMakeRange(15,1)].intValue) *4
            + ([value substringWithRange:NSMakeRange(6,1)].intValue + [value substringWithRange:NSMakeRange(16,1)].intValue) *2
            + [value substringWithRange:NSMakeRange(7,1)].intValue *1 + [value substringWithRange:NSMakeRange(8,1)].intValue *6
            + [value substringWithRange:NSMakeRange(9,1)].intValue *3;
    NSInteger remainder = summary % 11;
    NSString *checkBit = @"";
    NSString *checkString = @"10X98765432";
    checkBit = [checkString substringWithRange:NSMakeRange(remainder,1)];// 判断校验位
    return [checkBit isEqualToString:[[value substringWithRange:NSMakeRange(17,1)] uppercaseString]];
}


#pragma mark 获取运营商名称
/**获取运营商名称*/
+ (NSString *)getCarrierInfo
{
    CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = nil;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 12.1) {
        if ([telephonyInfo respondsToSelector:@selector(serviceSubscriberCellularProviders)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
            NSDictionary *dic = [telephonyInfo serviceSubscriberCellularProviders];
            if (dic.allKeys.count) {
                carrier = [dic objectForKey:dic.allKeys[0]];
            }
#pragma clang diagnostic pop
        }
    }
   
    if(!carrier) {
        //遇到的 warning 又明知干不掉的时候就用这种方法隐藏即可,-Wdeprecated-declarations
#pragma clang diagnostic push
#pragma clang diagnostic ignored  "-Wdeprecated-declarations"
        carrier = telephonyInfo.subscriberCellularProvider;
#pragma clang diagnostic pop
    }
    
    //countryCode，移动国家码，MCC的资源由国际电联（ITU）统一分配和管理，唯一识别移动用户所属的国家，共3位，中国为460;
    NSString *countryCode = [carrier mobileCountryCode];
    
    //code，移动网络码，共2位，中国移动TD系统使用00，中国联通GSM系统使用01，中国移动GSM系统使用02，中国电信CDMA系统使用03，一个典型的IMSI号码为460030912121001
    NSString *code = [carrier mobileNetworkCode];
    
    //网络运营商的名字
    NSString *carrier_name = @"";

    //用户运营商网络 （中国电信：CHINANET，中国联通：UNICOM，中国移动：CMNET，中国铁通：CRTC，中国广电：GCABLENET）
    if ([countryCode isEqualToString:@"460"] && countryCode && code) {
        if ([code isEqualToString:@"00"] || [code isEqualToString:@"02"] || [code isEqualToString:@"04"] || [code isEqualToString:@"07"] || [code isEqualToString:@"08"]|| [code isEqualToString:@"13"]) {
            carrier_name = @"CMNET";
        }
        else if ([code isEqualToString:@"03"] || [code isEqualToString:@"05"] || [code isEqualToString:@"11"] || [code isEqualToString:@"12"])
        {
            carrier_name =  @"CHINANET";
        }
        else if ([code isEqualToString:@"01"] || [code isEqualToString:@"06"] || [code isEqualToString:@"09"] || [code isEqualToString:@"10"])
        {
            carrier_name =  @"UNICOM";
        }
        else if ([code isEqualToString:@"20"])
        {
            carrier_name =  @"CRTC";
        }
        else if ([code isEqualToString:@"15"])
        {
            carrier_name =  @"GCABLENET";
        }
       
    }

    return  carrier_name;

}


@end
