React Native获取ios设备语言

时间:2017-10-17 11:20:37

标签: ios reactjs react-native

我正在尝试从ios设备获取当前的区域设置。

我在创建项目时跟随this guide,并且我使用了世博会。

我尝试了以下代码

 if (Platform.OS === "android") {
     langRegionLocale = NativeModules.I18nManager.localeIdentifier || "";
 } else if (Platform.OS === "ios") {
     langRegionLocale = NativeModules.SettingsManager.settings.AppleLocale || "";
 }

适用于Android ,但在iPhone上进行测试时,它无法正常工作,并且在我登录时说 SettingsManager未定义

如何在不弹出或使用AlexanderZaytsev/react-native-i18n 的情况下获取ios 的当前区域设置?

如果可能的话,我想使用内置的东西。

以下是我的 package.json

 {
  "name": "demoapp",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-native-scripts": "1.5.0",
    "jest-expo": "^21.0.2",
    "react-test-renderer": "16.0.0-alpha.12"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "expo": "^21.0.0",
    "react": "16.0.0-alpha.12",
    "react-native": "^0.48.4",
    "react-navigation": "^1.0.0-beta.13",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0"
  }
}

1 个答案:

答案 0 :(得分:0)

Expo Util API有一种获取设备区域设置的方法。

  

Expo.Util.getCurrentLocaleAsync()

     

返回当前设备   locale as a string。