2

Is it possible to ensure that after a fresh install of my code-pushified react-native app the user gets the latest deployed bundle from code-push?

My intention is to ensure that the user will always get the latest version of my app even after opening it for the first time.

EDIT 1

I am already aware of code-push configurations such as InstallMode and checkFrequency. I am currently using the less intrusive installMode = ON_NEXT_RESTART.

The scenario I want to avoid is the following: I first publish my app on the Play Store (let's do an Android example) with version 1.0.0. After, let's say, 6 months and a lot of new features and bug fixes my app is on version 1.0.27. If I only published the updates (the new versions) on code-push then the original apk available in Play Store still contains the bundle version 1.0.0. This means that any new user opening the app for the first time, right after installation, will get the 6-months-old 1.0.0 version without any of new the features and fixes that the latest version includes. Only after restarting the app (let's say it happens on the next day) the user will get the 1.0.27 version from code-push (remember that I am using installMode = ON_NEXT_RESTART).

The obvious solutions for this are:

  1. Publish a new apk on the Play Store for every new version of my app (besides, of course, publishing it on code-push).
  2. Use a more intrusive installMode.
  3. Mark every single code-push release as a mandatory install.

I am ok with the 1st option (and the 1st option only). I wanted to check if there is another option I am not aware of. To be honest I don't know if what I want is actually possible to do with code-push.

Augusto Altman Quaranta
  • 1,526
  • 1
  • 21
  • 32

1 Answers1

4

As per discussion in comments, what you wish to achieve can be achieved using manual updates of code push. To do so, you can set a variable in AsyncStorage to denote that you have opened app at least once, and if that doesn't exist control & immediately update the app. An example can be seen below;

class MyApp extends Component {
    componentDidMount() {
        AsyncStorage.getItem('@AppHasOpened').then((appHasOpened) => {
            if (!(appHasOpened && appHasOpened === 'yes')) {
                AsyncStorage.setItem('@AppHasOpened', 'yes').then(() => {
                    codePush.sync({
                        installMode: codePush.InstallMode.IMMEDIATE,
                    });
                });
            }
        });
    }
}
Tukan
  • 2,253
  • 15
  • 17
  • Thank you very much for your reply. I was aware of those configurations. I am currently using the less intrusive installMode = ON_NEXT_RESTART. I feel I should clarify my question a little further. I would like to avoid new users, that have just installed my app, to get a really old version on its first start, having to wait to a second start to get the latest. I don't know if what I want is actually possible to do with code-push. – Augusto Altman Quaranta Jan 07 '18 at 00:06
  • @AugustoAltmanQuaranta I have updated the answer to better reflect what you sought. This should give you what you want. – Tukan Jan 07 '18 at 00:21
  • 1
    It looks nice, but I believe that the `if` condition is reversed - the sync should be immediate if nothing is found on the AsyncStorage. – Danilo Moret Jan 30 '19 at 17:58