objective-cxcodemobile-country-code

Xcode 14+ serviceSubscriberCellularProviders mobileCountryCode return numbers instead of string?


i am trying to get mobileCountryCode from device sim operator.

the results i am getting from mobileCountryCode is 6553565535 which should be US or FR

here is my objective-C code

 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);

Print our result :

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

did i miss something ?

i am using xCode 14.3


Solution

  • serviceSubscriberCellularProvider is deprecated in iOS 16 and XCode 14.3 comes with iOS 16. https://developer.apple.com/documentation/coretelephony/cttelephonynetworkinfo/3024511-servicesubscribercellularprovide