How do i show the current CodePush Version label in my React Native Android app?
If there are no updates available, getUpdateMetadata() returns null...
Workaround:
import codePush from "react-native-code-push";
async function getAppVersion() {
const [{ appVersion }, update] = await Promise.all([
codePush.getConfiguration(),
codePush.getUpdateMetadata()
]);
if (!update) {
return `v${appVersion}`;
}
const label = update.label.substring(1);
return `v${appVersion} rev.${label}`;
};
export { getAppVersion };
Example output: v1.4.4" OR v1.4.4 rev.5" depending on state.
componentDidMount(){
codePush.getUpdateMetadata().then((metadata) =>{
this.setState({label: metadata.label, version: metadata.appVersion, description: metadata.description});
});
}
render() {
return(
<Text>{this.state.version}.{this.state.label}</Text>
);
}
Note: The .label
property is the internal build number used by CodePush (e.g. v24
)