Skip to content

Commit 05616ac

Browse files
committed
WIP
1 parent f71efe4 commit 05616ac

File tree

2 files changed

+9
-51
lines changed

2 files changed

+9
-51
lines changed

FirebasePhoneAuthUI/Sources/FUICountryCodes.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ NS_ASSUME_NONNULL_BEGIN
2626
@property (nonatomic, copy) NSString *dialCode;
2727
@property (nonatomic, copy) NSNumber *level;
2828

29+
/** @property defaultCountryCodeInfo
30+
@brief Get the default country code info
31+
Returns the default country code. Formerly this was set via CTCarrier information, but CTCarrier is now
32+
deprecated, so this value must be manually set.
33+
*/
34+
@property (nonatomic, copy) FUICountryCodeInfo *defaultCountryCodeInfo;
35+
2936
- (NSString *)countryFlagEmoji;
3037

3138
@end
@@ -55,16 +62,6 @@ NS_ASSUME_NONNULL_BEGIN
5562
*/
5663
- (nullable FUICountryCodeInfo *)countryCodeInfoForCode:(NSString *)countryCode;
5764

58-
/** @fn defaultCountryCodeInfo
59-
@brief Get the default country code info
60-
@detail The default country is retrieved based on the following logic:
61-
1. The country code info of user's carrier provider if available.
62-
2. The country code info of user's device locale, if available.
63-
3. A hard coded coutry code info (US), if available.
64-
4. The first available country code info in the instance.
65-
*/
66-
- (FUICountryCodeInfo *)defaultCountryCodeInfo;
67-
6865
/** @fn blacklistCountries:
6966
@brief Remove the set of countries from available country codes.
7067
@param countries A set of blacklisted country codes. Country codes are in NSString format, and

FirebasePhoneAuthUI/Sources/FUICountryCodes.m

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -114,48 +114,9 @@ - (FUICountryCodeInfo *)countryCodeInfoAtIndex:(NSInteger)index {
114114
}
115115

116116
- (FUICountryCodeInfo *)defaultCountryCodeInfo {
117-
// Get the country code based on the information of user's telecommunication carrier provider.
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-
}
148-
NSString *countryCode = carrier.isoCountryCode ?: [[self class] countryCodeFromDeviceLocale];
149-
FUICountryCodeInfo *countryCodeInfo = [self countryCodeInfoForCode:countryCode];
150-
// If carrier is not available, get the hard coded default country code.
151-
if (!countryCodeInfo) {
152-
countryCodeInfo = [self countryCodeInfoForCode:kFUIDefaultCountryCode];
117+
if (_defaultCountryCodeInfo == nil) {
118+
return [self countryCodeInfoForCode:kFUIDefaultCountryCode] ?: [self countryCodeInfoAtIndex:0];
153119
}
154-
// If the hard coded default country code is not available, get the first available country code.
155-
if (!countryCodeInfo) {
156-
countryCodeInfo = [self countryCodeInfoAtIndex:0];
157-
}
158-
return countryCodeInfo;
159120
}
160121

161122
- (FUICountryCodeInfo *)countryCodeInfoForPhoneNumber:(NSString *)phoneNumber {

0 commit comments

Comments
 (0)