Looking for something like:
<Text>VERSION={CodePush.VersionLabel}</Text>
Where CodePush.VersionLabel is something like "v6" that is displayed in code-push deployment ls <MyApp>
I'd like to show this at the bottom my login screen.
To initialize CodePush, we'll wrap our root component with a higher-order component provided by CodePush. We'll also add a few CodePush options, like a title tag for displaying live updates to users: import CodePush from 'react-native-code-push'; let CodePushOptions = { checkFrequency: CodePush. CheckFrequency.
Target binary version parameter This parameter specifies the store/binary version of the application you're releasing the update for, so that only users running that version will receive the update, while users running an older or newer version of the app binary won't.
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
)
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.getCurrentPackage().then((update)=> {
console.log('####### CodePush', update);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With