Listen for updates and reload whenever one is available

I am trying to set up a listener to check for updates and whenever one is available, download it and alert the user, then reload the app. I can’t seem to figure it out though, and the only functionality I can achieve is the default - whenever the app is completely closed and reopened, it will update.

My app.json fallbackToCacheTimeout is set to 30. In my root component of my app, on componentDidMount, I subscribe to Updates events, like follows:

componentDidMount = () => {
    this.updateSubscription = Updates.addListener(event => {
      if (event.type === Updates.EventType.DOWNLOAD_FINISHED) {
        Alert.alert('Update', "An update to the application was downloaded and will now be installed", [{
          text: 'Ok', onPress: () => {
            Updates.reload()
          }
        }], {
            cancelable: false
          })
      }
    })
  }

Hey @cshanno,

Just to be certain, are you trying to test this in your standalone app or within the Expo Client?

Cheers,
Adam

Testing this in a standalone app (Apple Enterprise Developer account if that matters). I have built the binary using expo and distributed it to a device managed by our business. I then make a change and use expo publish to create the update. The app picks it up if it is closed and then reopened, but I want it to:

  1. Update if the app is opened and an update is available
  2. Listen for updates always while the app is open and alert the user when an update is available

I may have misunderstood by stand-alone app. I am using the managed workflow, not bare bones workflow.

Hello,
I implemented a similar mechanism but relied on the application status change (I.e. app in background, app in foreground) and then checked if updates where available, if so force update and reload app.
Look at the documentation, I basically followed the example and it worked.
Also, in app.json the time is in msec so if you want 39 seconds fallback you should put 30000, in my case I have disabled the auto update feature as I implemented a custom one as described

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