androidiosreact-nativereact-native-device-info

How to get current country of Device in React Native (iOS and Android)?


I am trying to get current country of device in but didn't find anything. Is there something to do so in React Native? I tried using react-native-device-info but it is also not supporting but in previous version it can be get by getDeviceCountry(). Now for the latest version it is showing error:

TypeError: _reactNativeDeviceInfo.default.getDeviceCountry is not a function. (In '_reactNativeDeviceInfo.default.getDeviceCountry()', '_reactNativeDeviceInfo.default.getDeviceCountry' is undefined)


Solution

  • According to the documentation of react-native-device-info for latest version, they have moved some of their apis to react-native-localize to reduce duplication in the react-native-community modules. react-native-localize worked perfectly for me.

    Setup:

    $ npm install --save react-native-localize
    # --- or ---
    $ yarn add react-native-localize
    

    Usage:

    import * as RNLocalize from "react-native-localize";
    
    console.log(RNLocalize.getLocales());
    console.log(RNLocalize.getCurrencies());
    console.log(RNLocalize.getCountry());
    console.log(RNLocalize.getCalendar());
    console.log(RNLocalize.getTemperatureUnit());
    console.log(RNLocalize.getTimeZone());
    console.log(RNLocalize.uses24HourClock());
    

    and many more. For detailed description please visit their official documentation by the given link: react-native-localize