Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

双卡的时候怎么获取是哪个是流量卡 #5

Open
xhp281 opened this issue Jun 26, 2020 · 1 comment
Open

双卡的时候怎么获取是哪个是流量卡 #5

xhp281 opened this issue Jun 26, 2020 · 1 comment

Comments

@xhp281
Copy link

xhp281 commented Jun 26, 2020

No description provided.

@popor
Copy link

popor commented Aug 25, 2023

/// https://www.jianshu.com/p/f9c8d03c6579

  • (NSArray<CTCarrier *> *)simCardNumInPhone {
    //NSMutableArray * array = [NSMutableArray<CTCarrier *> new];
    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];

    //NSLogId(networkInfo.dataServiceIdentifier);
    //NSLogId(networkInfo.currentRadioAccessTechnology); // CTRadioAccessTechnologyLTE, 4G服务

    if (@available(iOS 12.0, *)) {
    NSDictionary *ctDict = networkInfo.serviceSubscriberCellularProviders;
    if ([ctDict allKeys].count > 1) {
    NSArray *keys = [ctDict allKeys];

          NSString * keyDefault = @"";
          if (@available(iOS 13, *)) {
              keyDefault = networkInfo.dataServiceIdentifier;
          }
          
          CTCarrier *carrier1 = nil;
          CTCarrier *carrier2 = nil;
          if ([keyDefault isEqualToString:keys.firstObject]) {
              carrier1 = [ctDict objectForKey:keys.firstObject];
              carrier2 = [ctDict objectForKey:keys.lastObject];
          } else {
              carrier2 = [ctDict objectForKey:keys.firstObject];
              carrier1 = [ctDict objectForKey:keys.lastObject];
          }
          
          if (carrier1.mobileCountryCode.length && carrier2.mobileCountryCode.length) {
              return @[carrier1, carrier2];
          }else if (carrier1.mobileCountryCode.length) {
              return @[carrier1];
          }else if (carrier2.mobileCountryCode.length) {
              return @[carrier2];
          }else {
              return nil;
          }
      }else if ([ctDict allKeys].count == 1) {
          NSArray *keys = [ctDict allKeys];
          CTCarrier *carrier1 = [ctDict objectForKey:[keys firstObject]];
          if (carrier1.mobileCountryCode.length) {
              return @[carrier1];
          }else {
              return nil;
          }
      }else {
          return nil;
      }
    

    }else {
    CTCarrier *carrier = [networkInfo subscriberCellularProvider];
    NSString *carrier_name = carrier.mobileCountryCode;
    if (carrier_name.length) {
    return @[carrier];
    }else {
    return nil;
    }
    }
    }

比较 networkInfo.dataServiceIdentifier 和 [ctDict allKeys];就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants