Xcode 14+ serviceSubscriberCellularProviders mobileCountryCode返回数字而不是字符串?

eqqqjvef  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(279)

我试图从设备SIM运营商获得mobileCountryCode.
我从mobileCountryCode得到的结果是6553565535,应该是USFR
下面是我Objective-C代码

CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
      CTCarrier *carrier = nil;
      // The CTTelephonyNetworkInfo.serviceSubscriberCellularProviders method crash because of an issue in iOS 12.0
      // It was fixed in iOS 12.1
      if (@available(iOS 12, *)) {
          NSDictionary<NSString *, CTCarrier *> *carriers = nil;
          if (@available(iOS 12.1, *)) {
              carriers = [networkInfo serviceSubscriberCellularProviders];
          } else {
              carriers = [networkInfo valueForKey:@"serviceSubscriberCellularProvider"];
          }
          if (carriers != nil) {
              for (NSString *key in carriers) {
                  carrier = carriers[key];
                  NSLog(@"isoCountryCode : %@", carrier.isoCountryCode.description);
              }
          }
      } else {
          carrier = [networkInfo subscriberCellularProvider];
      }

      NSString *codeInfo = @"";
      if (carrier != nil && carrier.mobileCountryCode != nil) {
          codeInfo = [carrier.mobileCountryCode stringByAppendingString:carrier.mobileNetworkCode];
      }

        NSLog(@"countryCode: %@", codeInfo.description);

打印我们的结果:

Carrier name: [--]
Mobile Country Code: [65535]
Mobile Network Code:[65535]
ISO Country Code:[--]
Allows VOIP? [YES]

我错过了什么吗?
我使用的是xCode 14.3

相关问题