美文网首页
iOS 获取手机中SIM卡数量

iOS 获取手机中SIM卡数量

作者: anny_4243 | 来源:发表于2022-10-17 17:47 被阅读0次
- (int)simCardNumInPhone {
    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
    if (@available(iOS 12.0, *)) {
        NSDictionary *ctDict = networkInfo.serviceSubscriberCellularProviders;
        if ([ctDict allKeys].count > 1) {
            NSArray *keys = [ctDict allKeys];
            CTCarrier *carrier1 = [ctDict objectForKey:[keys firstObject]];
            CTCarrier *carrier2 = [ctDict objectForKey:[keys lastObject]];
            if (carrier1.mobileCountryCode.length && carrier2.mobileCountryCode.length) {
                return 2;
            }else if (!carrier1.mobileCountryCode.length && !carrier2.mobileCountryCode.length) {
                return 0;
            }else {
                return 1;
            }
        }else if ([ctDict allKeys].count == 1) {
            NSArray *keys = [ctDict allKeys];
            CTCarrier *carrier1 = [ctDict objectForKey:[keys firstObject]];
            if (carrier1.mobileCountryCode.length) {
                return 1;
            }else {
                return 0;
            }
        }else {
            return 0;
        }
    }else {
        CTCarrier *carrier = [networkInfo subscriberCellularProvider];
        NSString *carrier_name = carrier.mobileCountryCode;
        if (carrier_name.length) {
            return 1;
        }else {
            return 0;
        }
    }
}

相关文章

网友评论

      本文标题:iOS 获取手机中SIM卡数量

      本文链接:https://www.haomeiwen.com/subject/izsdzrtx.html