我正在使用代码推送来更新我的react-native应用。如果我进行更新,我不希望每次都将其上传到App Store。我想将其直接推送到用户设备。
它工作正常,应用程序已更新,但我正在尝试显示更新成功的通知。
在docs他们这样做:
while($row = mysql_fetch_array($rs)){
$name = $row['first_name'];
$name2 = $row['first_name2'];
$lastname = $row['last_name'];
$lastname2 = $row['last_name2'];
$mellicode = $row['melli_code'];
$estekhdamnum = $row['estekhdam_num'];
$email = $row['email'];
$username = $row['username'];
$password = $row['password'];
echo("<script type='text/javascript'>
var table = document.getElementById('show_member');
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(i);
i = i+1;
// Insert new cells (<td> elements) at the 1st and 2nd position of the new <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);
var cell8 = row.insertCell(7);
var cell9 = row.insertCell(8);
// Add some text to the new cells:
cell1.innerHTML = '$name';
cell2.innerHTML = '$name2';
cell3.innerHTML = '$lastname';
cell4.innerHTML = '$lastname2';
cell5.innerHTML = '$mellicode';
cell6.innerHTML = '$estekhdamnum';
cell7.innerHTML = '$email';
cell8.innerHTML = '$username';
cell9.innerHTML = '$password';
</script>"
);
}
?>
<script type="text/javascript">
var index = 0;
var table = document.getElementById("show_member");
var length = table.rows.length;
var row;
alert(length);
for(index=1;index<table.rows.length-2;index++){
row = table.rows[index];
row.onmouseover = function(){
row.style.backgroundColor = 'red';
}
row.onmouseout = function(){
row.style.backgroundColor = '';
}
}
index = index+1;
table.rows[index].style.backgroundColor = 'green';
</script>
我正在尝试更新状态,如果更新成功并显示模态,并在按钮上单击隐藏它。因此我的代码如下:
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 */
}
);
但问题是模态会显示几秒钟后会消失,而不会点击按钮。
当状态设置为true,然后在我几秒钟后变为false
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>
);
}
知道怎么解决吗?
答案 0 :(得分:0)
在加载页面上尝试使用Codepush时,我也遇到了同样的问题,我的问题是在下一个屏幕上显示了CodePush的updateDialog。 因为codePush.sync是Promise函数,所以您可以使用其“ then”功能,它将确保以正确的顺序进行作业。
如果要使用CodePush,this demo可能会有所帮助。您可以在codePushStatusDidChange()中相应地更改组件的状态。