Any way to get version's of the app to distinguish each publish?

Is there any thing like codePush.getUpdateMetadata to get the current loaded version of the published app?
https://github.com/Microsoft/react-native-code-push/blob/master/docs/api-js.md#codepushgetupdatemetadata

I’m not sure if this accomplishes what you’re looking for but you can require('package.json') and then do something like

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

let pkg = require('./package.json');

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>{pkg.version}</Text>
      </View>
    );
  }
}

Does that meet your needs?

1 Like

This simply display the version defined in the package.json file right? I’m looking for something that will manage updating version itself after each exp publish.

We don’t have anything exactly like that right now, but you can request it here:

The code delivery system is one of the things we want to improve soon!

1 Like

Expo already handles updating the app to the latest version on a fresh start (when the app was not already running).

I needed to also have it check when the user comes back to our app and the app was already in the background, so I came up with this:

let isReloading = false;
async function reloadIfUpdateAvailable () {
  const {id,sdkVersion,revisionId} = Expo.Constants.manifest;
  if (!revisionId) return;

  const res = await fetch(`https://expo.io/${id}/index.exp`, {
    headers: {
    'Exponent-SDK-Version': sdkVersion,
    'Exponent-Platform': Platform.OS,
    },
    method: 'GET',
  });

  const json = await res.json();
  if (!json.revisionId) return;

  if (json.sdkVersion === sdkVersion) {
    if (json.revisionId !== revisionId) {
      if (!isReloading) {
        isReloading = true;
        Expo.Util.reload();
      }
    }
  }
  
}

I call reloadIfUpdateAvailable() when our app comes to the foreground from the background, and has been backgrounded for more than 3 seconds. Its a bit more complicated than just listening to AppState’s change event, since an active state is not sufficient alone. The app can go to inactive and back to active when a dialog/prompt pops up etc, plus you need to have a way to get the “time in background” number.

Hope this helps if you are trying to do something similar!

4 Likes

Cool! Thanks @joenoon.

Thanks @joenoon, pretty solution, it help me a lot

Constants.manifest.revisionId is combination of the app version and JS bundle ID. Perfect for my needs.