Expo.Updates.checkForUpdateAsync() never resolves in Expo sdk 31

#1

Running "expo": "^31.0.4"

I’m trying to inform my users that a new version is available and provide a button so they can reload the app to the newest version (already in cache).

The code as of now is like this:

constructor(props) {
    super(props);

    this.state = {
      loadingIfAnyUpdateAvailable: true,
      newVersionAvailable: false,
    };
  }

componentDidMount = () => {
    this.checkForUpdates();
  }

  checkForUpdates = async () => {
    let update;

      if (!__DEV__) {
        update = await Updates.checkForUpdateAsync();
      } else {
        update = false;
      }
    } catch (e) {
      console.log(e);
    }
    
    this.setState({
      loadingIfAnyUpdateAvailable: false,
      newVersionAvailable: update ? update.manifest.version : false,
    });

    if (update && update.isAvailable) {
      await Updates.fetchUpdateAsync();
    }
  }

  reloadApp = () => {
    Updates.reloadFromCache();
  }

  renderAppUpdates = () => {
    if (__DEV__) {
      return (
        <Text style={styles.appVersion}>
          Impossible to check for new versions in development.
        </Text>
      );
    }

    const { newVersionAvailable } = this.state;

    if (this.state.loadingIfAnyUpdateAvailable) {
      return (
        <Text style={styles.appVersion}>
          Checking to see if any new version exists...
        </Text>
      );
    } else if (newVersionAvailable) {
      return (
        <Text style={styles.appVersion}>
           New version is available! <Text onPress={this.reloadApp}>Click here to use it now!</Text>
        </Text>
      );
    }
    return (
      <Text style={styles.appVersion}>
        There are no updates available.
      </Text>
    );
  }

The problem is in production (standalone build) it seems the promise Updates.checkForUpdateAsync() never resolves in production, because this.state.loadingIfAnyUpdateAvailable the never changes to true.

I can’t debug the cause, because in development, the promise fails with [Error: Cannot fetch updates in dev mode]; even if I press p in expo CLI (and confirm __DEV__ === false, so I’m running in production), it still fails with that exact same message.

#2

Any luck on this? I’m looking at implementing something similar soon but haven’t tried publishing yet, just wondering if yours is still not working.

Also, probably just a copy/paste issue but I noticed your try/catch block is missing the try.

closed #3

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.