0

I'm trying to update my app with code-push. I have next code-push options in my index file:

let codePushOptions = {
    checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
    installMode: codePush.InstallMode.ON_NEXT_RESUME,
    minimumBackgroundDuration: 60 * 5
};

MainApp = codePush(codePushOptions)(Item);
export default MainApp;

Thus, on every app resume it will be checked if there is an update, but the update will be installed on next app resume.

But I want to show a button on a home screen to the users that the update is available if it is available, that they can install it manually on button click.

The problem is that the button is shown on main screen and they can see it if the update is still downloading in the background and if they click during the downloading process nothing happens. Only when the update is downloaded then the click on the button will install it. I try to AVOID that the button is show during downloading update.

I want to show the button only if the update is downloaded completely.

I check if the update is available in componentDidMount as follows:

checkForNewUpdate(){
        let self = this;
        codePush.checkForUpdate().then(update => {
            if (!update) {
                codePush.getUpdateMetadata(codePush.UpdateState.PENDING).then((data) => {
                    if (data) {
                        self.setState({updateAvailable: true, checkingForUpdate: false})
                    }else{
                        self.setState({updateAvailable: false, checkingForUpdate: false})
                    }
                });
            }else{
                self.setState({updateAvailable: true, checkingForUpdate: false})
            }
        })
    }

And I show button depending on the state as follows:

if(this.state.checkingForUpdate){
    return (
        <View style={{paddingTop: 10, paddingBottom: 10, alignItems: 'center'}}>
            <Text style={{color: s.success, fontSize: 12}}>{gettext("Checking for update...")}</Text>
        </View>
    )
}

if (this.state.updateAvailable){
    return (
        <View style={{flexDirection: "row", alignItems: "center", justifyContent: "center", padding: 5, backgroundColor: s.success}}>
            <Text style={styles.updateText}>{gettext("Update available")}</Text>
            <TouchableHighlight style={styles.updateButton} underlayColor={"transparent"} onPress={this.handleUpdate.bind(this)}>
                <Text style={styles.updateButtonText}>{gettext("Click to install")}</Text>
            </TouchableHighlight>
        </View>
    )
}

Any idea how to solve it?

Boky
  • 11,554
  • 28
  • 93
  • 163
  • Any solution found for this issue? – Tim Dirks Sep 29 '17 at 08:10
  • @TimDirks Unfortunately no. I'm going to as this question on the github page of the component and if the answer something I'll post it here. – Boky Sep 29 '17 at 08:13
  • Is the ON APP RESUME working on your side? – Tim Dirks Sep 29 '17 at 08:27
  • @TimDirks Yes, but not as `minimumBackgroundDuration ` says. It install it right after the app is resumed, never mind how long it has been in background. – Boky Sep 29 '17 at 08:29
  • @TimDirks I asked question on github page. [You can see it here.](https://github.com/Microsoft/react-native-code-push/issues/1024#issuecomment-333103865) – Boky Sep 29 '17 at 12:21
  • @Boky - I'm trying to answer this question but I'd appreciate it if you could edit the question for clarity. The questions I have are: 1) Please change instances of "the button" to the Check for Update or Install Update button (I'm assuming there are two buttons) 2) Show the initial state for updateAvailable and checkingForUpdate 3) In checkForNewUpdate - Explain why you are getting update metadata when !update (app is up-to-date case) as that seems incorrect for your purposes and may make the question moot. – huntharo Oct 27 '17 at 17:09

0 Answers0