@@ -57,6 +57,31 @@ - (NSString *)countryFlagEmoji {
5757 length: sizeof (bytes)
5858 encoding: NSUTF32LittleEndianStringEncoding];
5959}
60+
61+ - (id )copyWithZone : (NSZone *_Nullable)zone {
62+ FUICountryCodeInfo *newInfo = [[FUICountryCodeInfo alloc ] init ];
63+ newInfo.countryName = self.countryName ;
64+ newInfo.localizedCountryName = self.localizedCountryName ;
65+ newInfo.countryCode = self.countryCode ;
66+ newInfo.dialCode = self.dialCode ;
67+ newInfo.level = self.level ;
68+ return newInfo;
69+ }
70+
71+ - (BOOL )isEqual : (FUICountryCodeInfo *)object {
72+ if (object == self) {
73+ return YES ;
74+ }
75+ if (![object isKindOfClass: [self class ]]) {
76+ return NO ;
77+ }
78+ return object.countryName == self.countryName &&
79+ object.localizedCountryName == self.localizedCountryName &&
80+ object.countryCode == self.countryCode &&
81+ object.dialCode == self.dialCode &&
82+ object.level == self.level ;
83+ }
84+
6085@end
6186
6287@interface FUICountryCodes ()
@@ -114,48 +139,10 @@ - (FUICountryCodeInfo *)countryCodeInfoAtIndex:(NSInteger)index {
114139}
115140
116141- (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
142+ if (_defaultCountryCodeInfo == nil ) {
143+ return [self countryCodeInfoForCode: kFUIDefaultCountryCode ] ?: [self countryCodeInfoAtIndex: 0 ];
147144 }
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 ];
153- }
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;
145+ return _defaultCountryCodeInfo;
159146}
160147
161148- (FUICountryCodeInfo *)countryCodeInfoForPhoneNumber : (NSString *)phoneNumber {
0 commit comments