@@ -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