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?