Updates.addListener not working

Please provide the following:

  1. SDK Version: ~41.0.0
  2. Platforms(Android/iOS/web/all): Android

I’m trying to use Updates.addListener to download and install updates without the user needing to close the app but my listener callback is never called. I’m testing with Expo Go and a published release channel on an Android phone. My app.json is has the updates configuration set as follows:

updates: {
    fallbackToCacheTimeout: 0,
    checkAutomatically: 'ON_LOAD'
  }

Here is the code in App.tsx:

  useEffect(() => {
    const eventListener = async (event: Updates.UpdateEvent) => {
      Alert.alert('Callback');
      if (event.type === Updates.UpdateEventType.UPDATE_AVAILABLE) {
        try {
          const { isNew } = await Updates.fetchUpdateAsync();
          if (isNew) {
            Updates.reloadAsync();
          }
        } catch (error) {
          console.log('Unable to feth the update and reload');
        }
      }
    };
    const subscription = Updates.addListener(eventListener);
    return () => {
      subscription.remove();
    };
  }, []);

Hi! Looks like you are expecting that the callback fires when new bundle is available on the server. But with addListener you can only get event when the new bundle is already downloaded on the client. We discussed it here

1 Like

It turns out that the above code does work. It simply takes from time after publishing the new version for Updates.addListener to send an event to the callback

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