Skip to content

Commit 03acf0a

Browse files
committed
Add multi-sim support for phone auth
1 parent 7aad210 commit 03acf0a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

PhoneAuth/FirebasePhoneAuthUI/CountryCode/FUICountryCodes.m

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,36 @@ - (FUICountryCodeInfo *)countryCodeInfoAtIndex:(NSInteger)index {
115115

116116
- (FUICountryCodeInfo *)defaultCountryCodeInfo {
117117
// Get the country code based on the information of user's telecommunication carrier provider.
118-
CTCarrier *carrier = [[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider];
118+
CTCarrier *carrier;
119+
if (@available(iOS 12, *)) {
120+
NSDictionary *carriers =
121+
[[[CTTelephonyNetworkInfo alloc] init] serviceSubscriberCellularProviders];
122+
// For multi-sim phones, use the current locale to make an educated guess for
123+
// which carrier to use.
124+
NSString *currentCountryCode = [NSLocale currentLocale].countryCode;
125+
for (CTCarrier *provider in carriers.allValues) {
126+
if ([provider isKindOfClass:[CTCarrier class]] &&
127+
[provider.isoCountryCode isEqualToString:currentCountryCode]) {
128+
carrier = provider;
129+
break;
130+
}
131+
}
132+
133+
// If the carrier is still nil, grab a random carrier from the dictionary.
134+
if (carrier == nil) {
135+
for (CTCarrier *provider in carriers.allValues) {
136+
if ([provider isKindOfClass:[CTCarrier class]]) {
137+
carrier = provider;
138+
break;
139+
}
140+
}
141+
}
142+
} else {
143+
#pragma clang diagnostic push
144+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
145+
carrier = [[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider];
146+
#pragma clang diagnostic pop
147+
}
119148
NSString *countryCode = carrier.isoCountryCode ?: [[self class] countryCodeFromDeviceLocale];
120149
FUICountryCodeInfo *countryCodeInfo = [self countryCodeInfoForCode:countryCode];
121150
// If carrier is not available, get the hard coded default country code.

0 commit comments

Comments
 (0)