Checking the code to update

I am trying to update my application with code input. My code looks like this:

export default class codePushTest extends Component {
    constructor(props) {
        super(props);
        this.state = {
            updateAvailable: false,
            downloadingUpdate: null,
            installingUpdate: null,
            downloadProgress: null,
        }
    }

    componentDidMount() {
        let self = this;
        codePush.checkForUpdate().then(update => {
            if (!update) {
                self.setState({updateAvailable: false})
            }else{
                self.setState({updateAvailable: true})
            }
        })
    }

    handleUpdate() {
        let self = this;
        const checkUpdateStatus = (status) => {
            switch (status) {
                case codePush.SyncStatus.DOWNLOADING_PACKAGE:
                    self.setState({downloadingUpdate: true});
                    break;
                case codePush.SyncStatus.INSTALLING_UPDATE:
                    self.setState({installingUpdate: true, downloadingUpdate: false});
                    break;
                case codePush.SyncStatus.UPDATE_INSTALLED:
                    self.setState({installingUpdate: false, downloadingUpdate: false, updateInstalled: true});
                    break;
            }
        };

        const downloadProgress = (downloadedBytes, totalBytes) => {
            self.setState({downloadProgress: (downloadedBytes / totalBytes) * 100})
        };

        codePush.sync({updateDialog: false, installMode: codePush.InstallMode.IMMEDIATE}, checkUpdateStatus, downloadProgress)
    }

    renderButton(){
        if (this.state.updateAvailable){
            return (
                <View style={{marginTop: 40}}>
                    <TouchableHighlight onPress={this.handleUpdate.bind(this)}>
                        <Text>An update is available.</Text>
                    </TouchableHighlight>
                </View>
            )
        }

    }

    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.welcome}>Welcome message. </Text>
                {this.renderButton()}
            </View>
        )
    }
}

      

So I'm trying to check if an update is available in componentDidMount

, and if there is, then update the state and depending on that button, update the state.

But the problem is when I click the code and this is the newest code in the application, it still shows the button An update available

.

If I change the content of my application and send it to the server with the code code-push release-react AppName ios

, the button is displayed again, that's good. If I click on it, the new content is shown and the button disappears, which is good.

But the problem is, if I update the app, I get the old content again and the button is displayed again. And if I click on it again, nothing happens.

Any idea what I am doing wrong?

+3


source to share


1 answer


The component must be wrapped with a code pair. I haven't seen it in the docs. Here is the link.

Thus:

Instead



export default Item;

      

he should be

let codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };
MainApp = codePush(codePushOptions)(Item);
export default MainApp;

      

0


source







All Articles