Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i show the current CodePush Version label in my React Native Android app?

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.

like image 954
Doug Avatar asked Sep 30 '16 17:09

Doug


People also ask

How do I add CodePush to React Native?

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.

What is target binary version?

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.


3 Answers

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)

like image 52
Doug Avatar answered Oct 19 '22 05:10

Doug


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.

like image 23
Greg R Taylor Avatar answered Oct 19 '22 05:10

Greg R Taylor


componentDidMount() {
 CodePush.getCurrentPackage().then((update)=> {
    console.log('####### CodePush', update);
 });
}
like image 4
Giang Avatar answered Oct 19 '22 05:10

Giang