React-native: NativeModules.SettingsManager.settings.AppleLocale not working in ios 13

Created on 23 Sep 2019  路  5Comments  路  Source: facebook/react-native

I used NativeModules.SettingsManager.settings.AppleLocale to define interface language in my app. After updating xcode to version 11.0 (11A420a) and run in emulator on ios 13 it stopped work.

Settings iOS Ran Commands Question

Most helpful comment

Yes.

When you launch the fresh simulator or you have a device with language without a region, AppleLocale is nowhere to be found in NSUserDefaults on iOS 13. Now when you do change it to, for example, English(Canada) -> it's there.

Workaround:

let locale = NativeModules.SettingsManager.settings.AppleLocale // "fr_FR"
if (locale === undefined) {
    // iOS 13 workaround, take first of AppleLanguages array  ["en", "en-NZ"]
    locale = NativeModules.SettingsManager.settings.AppleLanguages[0]
    if (locale == undefined) {
          locale = "en" // default language
    }
}

Similar issue on expo here: expo/expo#5735 (comment)

As per my understanding the problem is that if the phone (either device or simulator) has the default language because the user didn't set it, all the language properties like timezone, country, currency and so on are undefined raising the exception
I'm able to reproduce the issue with iOS13 on a fresh simulator or on some devices.
Changing the language in "settings" to English/UK or English/US, the Localization.* properties are set properly.

All 5 comments


We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

馃憠 Click here if you want to report a reproducible bug or regression in React Native.

I'm in the same situation. Does anyone managed to get it working?

Yes.

When you launch the fresh simulator or you have a device with language without a region, AppleLocale is nowhere to be found in NSUserDefaults on iOS 13. Now when you do change it to, for example, English(Canada) -> it's there.

Workaround:

let locale = NativeModules.SettingsManager.settings.AppleLocale // "fr_FR"
if (locale === undefined) {
    // iOS 13 workaround, take first of AppleLanguages array  ["en", "en-NZ"]
    locale = NativeModules.SettingsManager.settings.AppleLanguages[0]
    if (locale == undefined) {
          locale = "en" // default language
    }
}

Similar issue on expo here: expo/expo#5735 (comment)

As per my understanding the problem is that if the phone (either device or simulator) has the default language because the user didn't set it, all the language properties like timezone, country, currency and so on are undefined raising the exception
I'm able to reproduce the issue with iOS13 on a fresh simulator or on some devices.
Changing the language in "settings" to English/UK or English/US, the Localization.* properties are set properly.

More or less, that was what I was going to do, but I was waiting if there was another way.
Thanks a lot
Much appreciated

Was this page helpful?
0 / 5 - 0 ratings

Related issues

despairblue picture despairblue  路  3Comments

josev55 picture josev55  路  3Comments

oney picture oney  路  3Comments

janmonschke picture janmonschke  路  3Comments

DreySkee picture DreySkee  路  3Comments