Expo How to check which app version user installed?

1.2k Views Asked by At
 Constants.manifest.version

gives me the app version. Is there any way to see the version a user installed or would I need to store it somewhere like db and then always fetch from db and compare it with the version to know if user has an older version installed?

EDIT: What I am trying to do:

If there was an update, I want to be able to sometimes show a pop up to users that tells them there was an update and potentionally in very few cases i want to then force the user to upgrade. So for that I would need to compare the version the user has installed with the version in the app store/google play and if users version is lower, I send the popup. I would also have some logic to determine if its only a update recommendation or force update. Not sure yet how, but maybe another entry in the db for each version and boolean with boolean forceUpgrade/recommendedUpgrade

1

There are 1 best solutions below

0
WM1 On

I'm handling version based updates manually, using AsyncStorage and two global constants:

Upon mount, extract storedAppVersion from AsyncStorage. Compare storedAppVersion with hardcoded CURRENT_APP_VERSION, and if there's a change, and if hardcoded RESET_ON_VERSION_CHANGE is true, forceUpdate!

Update occurs

  • only the first time the Version changes and
  • only if RESET_ON_VERSION_CHANGE is true

after update, store CURRENT_APP_VERSION for subsequent versions (ie. .then() or button press).

Conceptual Snippet:


const CURRENT_APP_VERSION 
const RESET_ON_VERSION_CHANGE 
.
.
.

 useEffect(() => {
    const fetchDataFromAsyncStorage = async () => {
      try {
        const storedData = await getDataFromAsyncStorage();
        if (storedData) { const { appVersion: storedAppVersion, } = storedData;


      if (storedAppVersion != CURRENT_APP_VERSION) {
        if (storedAppVersion != null) {
          if (RESET_ON_VERSION_CHANGE) {
            deleteEverything().then(() => {
              console.log('DeleteEverything completed');
            });
            return;
          }
        }
      }
    fetchDataFromAsyncStorage();
  }, []);