Skip to content

Commit

Permalink
Added serviceSubscriberCellularProviders for loop to check for isoCou…
Browse files Browse the repository at this point in the history
…ntryCode
  • Loading branch information
FONickReichard committed Oct 11, 2022
1 parent 074dc60 commit 7c19894
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions libPhoneNumber/NBPhoneNumberUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -3496,15 +3496,23 @@ - (CTTelephonyNetworkInfo *)telephonyNetworkInfo {
}

- (NSString *)countryCodeByCarrier {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_12_0
NSDictionary<NSString *, CTCarrier *> *serviceSubscriberCellularProviders = [self.telephonyNetworkInfo serviceSubscriberCellularProviders];
CTCarrier *carrier = serviceSubscriberCellularProviders.allValues.firstObject;
NSMutableSet *isoCountryCodes = [NSMutableSet set];

if (carrier == nil) {
return NB_UNKNOWN_REGION;
for (CTCarrier *carrier in [serviceSubscriberCellularProviders allValues]) {
NSString *isoCountryCode = [carrier isoCountryCode];

if (isoCountryCode != nil) {
[isoCountryCodes addObject: isoCountryCode];
}
}

return carrier.isoCountryCode;
// If all cellular providers have the same isoCountryCode, return it
if (isoCountryCodes.count == 1) {
return [isoCountryCodes anyObject];
}
// There are none or multiple carriers, can't determine which to use
return NB_UNKNOWN_REGION;
#else
NSString *isoCode = [[self.telephonyNetworkInfo subscriberCellularProvider] isoCountryCode];

Expand Down

0 comments on commit 7c19894

Please sign in to comment.