diff --git a/App.js b/App.js
index 4618b33..cd5a098 100644
--- a/App.js
+++ b/App.js
@@ -106,6 +106,25 @@ export default class MyPage extends Component {
versionInfo:'未知'
};
}
+
+//更新函数
+codePushUpdate() {
+ CodePush.allowRestart();
+ CodePush.sync(
+ { installMode: CodePush.InstallMode.IMMEDIATE},
+ this.codePushStatusDidChange.bind(this),
+ this.codePushDownloadDidProgress.bind(this)
+ );
+
+ CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
+ .then((metadata: LocalPackage) => {
+ this.setState({ versionInfo: metadata ? metadata.appVersion +'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : "Unknown"});
+ }, (error: any) => {
+ this.setState({ versionInfo: "Unknown"});
+ });
+}
+
+
// 监听更新状态
codePushStatusDidChange(syncStatus) {
switch(syncStatus) {
@@ -168,39 +187,42 @@ codePushStatusDidChange(syncStatus) {
+encodeURIComponent(this.state.macAddress),
{version:this.state.versionInfo})
.then(result => {
- let config = JSON.parse(result.data.config);
- this.setState({
- heartConfig:{
- heartbeatInterval:config.heartbeatInterval,
- dataRefreshInterval:config.dataRefreshInterval,
- pageChangeInterval:config.pageChangeInterval
- }
- })
- // 动画划入
- if(config.animationTheme == 0){
- this.setState({
- animationTheme:animationThemes[0]
- })
- }else if(config.animationTheme == 1){
- // 放大
+ if (result.code == 200) {
+ let config = JSON.parse(result.data.config);
this.setState({
- animationTheme:animationThemes[1]
- })
- }else if(config.animationTheme == 2){
- // 淡入
- this.setState({
- animationTheme:animationThemes[2]
- })
- }else if(config.animationTheme == 3){
- // 弹入
- this.setState({
- animationTheme:animationThemes[3]
+ heartConfig:{
+ heartbeatInterval:config.heartbeatInterval,
+ dataRefreshInterval:config.dataRefreshInterval,
+ pageChangeInterval:config.pageChangeInterval
+ }
})
+ // 动画划入
+ if(config.animationTheme == 0){
+ this.setState({
+ animationTheme:animationThemes[0]
+ })
+ }else if(config.animationTheme == 1){
+ // 放大
+ this.setState({
+ animationTheme:animationThemes[1]
+ })
+ }else if(config.animationTheme == 2){
+ // 淡入
+ this.setState({
+ animationTheme:animationThemes[2]
+ })
+ }else if(config.animationTheme == 3){
+ // 弹入
+ this.setState({
+ animationTheme:animationThemes[3]
+ })
+ }
+ } else {
+ //do nothing
}
-
+
})
.catch(error => {
- console.warn(error)
this.setState({ errorMessage : error});
})
}
@@ -247,19 +269,8 @@ codePushStatusDidChange(syncStatus) {
}
componentDidMount() {
- CodePush.allowRestart();
- CodePush.sync(
- { installMode: CodePush.InstallMode.IMMEDIATE},
- this.codePushStatusDidChange.bind(this),
- this.codePushDownloadDidProgress.bind(this)
- );
+ this.codePushUpdate();
- CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
- .then((metadata: LocalPackage) => {
- this.setState({ versionInfo: metadata ? metadata.appVersion +'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : "Unknown"});
- }, (error: any) => {
- this.setState({ versionInfo: "Unknown"});
- });
DeviceInfo.getMACAddress().then((mac)=>{
if (mac=='' || mac==null ) {
if (NativeModules.BuildConfig.buildType == 'debug') {
@@ -280,7 +291,6 @@ componentDidMount() {
}
-
startAd() {
this.getBaseInfo()
this.getAdDataList()
@@ -414,21 +424,24 @@ getContentView() {
}
}
-render() {
-
- if (this.state.progress) {
- if (this.state.progress.totalBytes > 0)
- return (
- {this.state.syncMessage}{'\n'}
- {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'}
-
- );
+getUpdateView() {
+ if (this.state.progress.totalBytes > 0)
return (
- {this.state.syncMessage}
+ {this.state.syncMessage}{'\n'}
+ {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'}
);
- }
+ return (
+ {this.state.syncMessage}
+
+ );
+}
+
+render() {
+ if (this.state.progress) {
+ this.getUpdateView();
+ }
return (