首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在我的应用程序中显示当前的CodePush版本标签?

如何在我的应用程序中显示当前的CodePush版本标签?
EN

Stack Overflow用户
提问于 2016-09-30 17:00:14
回答 4查看 11.5K关注 0票数 19

寻找类似的东西:<Text>VERSION={CodePush.VersionLabel}</Text>

其中CodePush.VersionLabel类似于code-push deployment ls <MyApp>中显示的"v6“

我想在我的登录屏幕底部显示这个。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-10-02 05:39:38

代码语言:javascript
复制
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>
    );
}

注意:.label属性是CodePush使用的内部构建号(例如v24)

票数 30
EN

Stack Overflow用户

发布于 2019-06-24 05:27:01

如果没有可用的更新,getUpdateMetadata()将返回null.

解决办法:

代码语言:javascript
复制
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 };

示例输出:v1.4.4"v1.4.4 re.5“取决于状态。

票数 7
EN

Stack Overflow用户

发布于 2016-12-29 02:46:04

代码语言:javascript
复制
componentDidMount() {
 CodePush.getCurrentPackage().then((update)=> {
    console.log('####### CodePush', update);
 });
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39796511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档