From d3584d73d2438c10699d21b7e6dfb3e3810e4b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kosmaty?= Date: Tue, 15 Oct 2019 16:21:00 +0200 Subject: [PATCH] [localization] Fix exporting `region` constant (#5740) # Why Resolve #5735. # How Wrapped `region` variable into UMNullIfNil macro, because `[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]` could return nil on iOS simulator. --- .../ios/EXLocalization/EXLocalization.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/expo-localization/ios/EXLocalization/EXLocalization.m b/packages/expo-localization/ios/EXLocalization/EXLocalization.m index 347067e7f3ec4..d6a29fc74edb6 100644 --- a/packages/expo-localization/ios/EXLocalization/EXLocalization.m +++ b/packages/expo-localization/ios/EXLocalization/EXLocalization.m @@ -21,6 +21,14 @@ @implementation EXLocalization - (NSDictionary *)constantsToExport { NSArray *preferredLocales = [NSLocale preferredLanguages]; + if (preferredLocales == nil) { + NSString *currentLocale = [[NSLocale currentLocale] localeIdentifier]; + if (currentLocale == nil) { + currentLocale = @"en_US"; + } + preferredLocales = @[currentLocale]; + } + NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone]; NSString *region = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]; @@ -30,7 +38,7 @@ - (NSDictionary *)constantsToExport @"locales": preferredLocales, @"timezone": [currentTimeZone name], @"isoCurrencyCodes": [NSLocale ISOCurrencyCodes], - @"region": region + @"region": UMNullIfNil(region) }; }