react-nativereact-native-webreact-native-device-info

Set and get app version name and app version code for react-native-web application


Is there a way to set an app version and build number for a react-native-web app?

I am currently using react-native-web for an app (for IOS, Android and Web).

I am also using react-native-device-info.

Currently for web when I use:

DeviceInfo.getReadableVersion() or DeviceInfo.getVersion() or DeviceInfo.getBuildNumber() I get only 0.0 and 0.

Getting the version and build number works perfect for android and iOS but I have no idea how to set it and get it for web.


Solution

  • There is no way to get a version of a website, because there is no .apk or .ipa installed on the browser. I suggest you create your own version system, and put it in some meta tag:

    <meta name="my-app-version" content="1.0.0" />

    Also you can do this directly on your JS code:

    export const APP_VERSION = "1.0.0"

    Control version in the browser is less required than in the native side. Only do this if you need to force the user to update to the last version, as example: you can force the user to refresh the page and download the last bundle if version is different from and API endpoint that you configured.

    Users will eventually refresh or close the tabs of the browser and when they come back, the last version of the code will be available.