React native 使用代码推送成功更新时的更新状态

React native 使用代码推送成功更新时的更新状态,react-native,code-push,react-native-code-push,React Native,Code Push,React Native Code Push,我正在使用代码推送更新我的react本机应用程序。我不想每次更新时都将其上传到App Store,我想直接将其推送到用户设备上 它工作正常,应用程序已更新,但我正在尝试显示一个通知,如果更新成功 在这方面,他们的做法如下: codePush.sync({ updateDialog: true }, (status) => { switch (status) { case codePush.SyncStatus.DOWNLOADING_PACKAGE:

我正在使用代码推送更新我的react本机应用程序。我不想每次更新时都将其上传到App Store,我想直接将其推送到用户设备上

它工作正常,应用程序已更新,但我正在尝试显示一个通知,如果更新成功

在这方面,他们的做法如下:

codePush.sync({ updateDialog: true },
  (status) => {
      switch (status) {
          case codePush.SyncStatus.DOWNLOADING_PACKAGE:
              // Show "downloading" modal
              break;
          case codePush.SyncStatus.INSTALLING_UPDATE:
              // Hide "downloading" modal
              break;
      }
  },
  ({ receivedBytes, totalBytes, }) => {
    /* Update download modal progress */
  }
);
constructor() {
        super();
        this.state = {
            modalVisible: false,
            status: ""
        }
    }

    componentDidMount() {
        let self = this;
        codePush.sync({
                updateDialog: true,
                installMode: codePush.InstallMode.IMMEDIATE
            }, (status) => {
                switch (status) {
                    case codePush.SyncStatus.UPDATE_INSTALLED:
                        self.setState({modalVisible: true});
                        break;
                }
            },
            ({receivedBytes, totalBytes,}) => {
                /* Update download modal progress */
                self.setState({status: "Downloaded " + receivedBytes + " of " + totalBytes});
            }
        );
    }

    renderUpdateNotificationModal(){
        return (
            <Modal
                animationType={"slide"}
                transparent={false}
                visible={this.state.modalVisible}
                onRequestClose={() => {alert("Modal has been closed.")}}
            >
                <View style={{marginTop: 22}}>
                    <View>
                        <Text>Updated</Text>
                        <TouchableHighlight onPress={() => {this.setState({modalVisible: false})}}>
                            <Text>OK</Text>
                        </TouchableHighlight>
                    </View>
                </View>
            </Modal>
        )
    }

    render() {
        return (
            <View style={styles.container}>
                {this.renderUpdateNotificationModal()}
                <Text style={styles.welcome}>
                    Welcome!
                </Text>
                <Text style={styles.instructions}>
                    To get started, edit index.ios.js
                </Text>
                <Text style={styles.instructions}>
                    Press Cmd+R to reload,{'\n'}
                    Cmd+D or shake for dev menu
                </Text>
                <Text style={{fontSize: 18, marginTop: 15, color: "blue", textAlign: "center"}}>{this.state.status}</Text>
            </View>
        );
    }
如果更新成功,我将尝试更新状态,并显示模式,单击按钮可将其隐藏。因此,我的代码如下:

codePush.sync({ updateDialog: true },
  (status) => {
      switch (status) {
          case codePush.SyncStatus.DOWNLOADING_PACKAGE:
              // Show "downloading" modal
              break;
          case codePush.SyncStatus.INSTALLING_UPDATE:
              // Hide "downloading" modal
              break;
      }
  },
  ({ receivedBytes, totalBytes, }) => {
    /* Update download modal progress */
  }
);
constructor() {
        super();
        this.state = {
            modalVisible: false,
            status: ""
        }
    }

    componentDidMount() {
        let self = this;
        codePush.sync({
                updateDialog: true,
                installMode: codePush.InstallMode.IMMEDIATE
            }, (status) => {
                switch (status) {
                    case codePush.SyncStatus.UPDATE_INSTALLED:
                        self.setState({modalVisible: true});
                        break;
                }
            },
            ({receivedBytes, totalBytes,}) => {
                /* Update download modal progress */
                self.setState({status: "Downloaded " + receivedBytes + " of " + totalBytes});
            }
        );
    }

    renderUpdateNotificationModal(){
        return (
            <Modal
                animationType={"slide"}
                transparent={false}
                visible={this.state.modalVisible}
                onRequestClose={() => {alert("Modal has been closed.")}}
            >
                <View style={{marginTop: 22}}>
                    <View>
                        <Text>Updated</Text>
                        <TouchableHighlight onPress={() => {this.setState({modalVisible: false})}}>
                            <Text>OK</Text>
                        </TouchableHighlight>
                    </View>
                </View>
            </Modal>
        )
    }

    render() {
        return (
            <View style={styles.container}>
                {this.renderUpdateNotificationModal()}
                <Text style={styles.welcome}>
                    Welcome!
                </Text>
                <Text style={styles.instructions}>
                    To get started, edit index.ios.js
                </Text>
                <Text style={styles.instructions}>
                    Press Cmd+R to reload,{'\n'}
                    Cmd+D or shake for dev menu
                </Text>
                <Text style={{fontSize: 18, marginTop: 15, color: "blue", textAlign: "center"}}>{this.state.status}</Text>
            </View>
        );
    }

知道怎么解决吗?

我在加载页面尝试使用Codepush时遇到了类似的问题,我的问题是Codepush的updateDialog显示在下一个屏幕上。 因为codePush.sync是一个Promise函数,您可以使用它的“then”功能,它将确保按正确的顺序完成您的工作


如果您想使用CodePush,可能会有所帮助。您可以在codePushStatusDidChange()中相应地更改组件的状态。

我在加载页面尝试使用Codepush时遇到了类似的问题,我的问题是Codepush的updateDialog显示在下一个屏幕上。 因为codePush.sync是一个Promise函数,您可以使用它的“then”功能,它将确保按正确的顺序完成您的工作


如果您想使用CodePush,可能会有所帮助。您可以在codePushStatusDidChange()中相应地更改组件的状态。

安装更新后是否有任何闪屏?我想你的应用程序是restarted@Jiro267否。显示模式,然后在一秒钟后消失,我看到更新的屏幕。屏幕不闪烁。
installMode:codePush.installMode.IMMEDIATE
这应该是根据强制重新启动应用程序。你确定它不会重新启动和初始化太快(上面的应用程序非常小!)以至于你把它误认为是模式关闭和状态重置吗?他似乎指出了这一点。解决方案是
codePush.InstallMode。下一次\u重新启动
codePush.InstallMode。下一次\u恢复安装更新后是否有闪屏?我想你的应用程序是restarted@Jiro267否。显示模式,然后在一秒钟后消失,我看到更新的屏幕。屏幕不闪烁。
installMode:codePush.installMode.IMMEDIATE
这应该是根据强制重新启动应用程序。你确定它不会重新启动和初始化太快(上面的应用程序非常小!)以至于你把它误认为是模式关闭和状态重置吗?他似乎指出了这一点。解决方案是
codePush.InstallMode.ON\u NEXT\u重新启动
codePush.InstallMode.ON\u NEXT\u恢复