3
我試圖用代碼推送更新我的應用程序。我的代碼如下:代碼推送檢查更新
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>
)
}
}
因此,我想要是檢查是否存在componentDidMount
可用的更新,如果是,則更新狀態,並根據該狀態顯示更新按鈕。
但問題是,當我推動代碼,它是應用程序中的最新代碼時,它仍然顯示按鈕An update available
。
如果我更改我的應用程序的內容並將其發送到代碼推送服務器code-push release-react AppName ios
,該按鈕再次顯示,這很好。 如果點擊它,會顯示新內容,並且按鈕會消失,這很好。
但問題是,如果我刷新應用程序,我再次得到舊內容,並再次顯示按鈕。如果我再次點擊它,沒有任何反應。
任何想法,我究竟做錯了什麼?