React Native Android不保持Codepush更新

时间:2019-09-20 13:27:57

标签: android react-native code-push

我已经按照我的判断告诉您正确设置Codepush的正确步骤,但是iOs应用程序似乎是唯一可以更新应用程序并保持更新的程序。 Android似乎重新启动,然后再次重新启动,并且似乎未应用该更新。这是我目前对react-native和android的设置

index.js

import {AppRegistry, NativeModules} from 'react-native';
import Main from './Main';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => Main);

Main.js

import { StyleProvider } from "native-base";
import { Provider } from 'react-redux';
import App from './components/App';
import store from './store';
import getTheme from './native-base-theme/components';
import material from './native-base-theme/variables/material';
import codePush from "react-native-code-push";
import { PortalProvider } from 'react-native-portal'

let codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };

class Main extends Component {
  render() {
    return (
      <Provider store={store}>
        <StyleProvider style={getTheme(material)}>
          <PortalProvider>
            <App />
          </PortalProvider>
        </StyleProvider>
      </Provider>
    )
  }
}
export default codePush(codePushOptions)(Main);

App内,我呈现了一个Menu,它实际上负责寻找新的更新并通知用户

Menu

componentWillMount() {
    codePush.disallowRestart();
    if (process.env.NODE_ENV === 'production') {
      Sentry.init({
        dsn: "***"
      })
      codePush.getUpdateMetadata().then((update) => {
        if (update) {
          Sentry.setRelease(`${version}-codepush:${update.label}`);
        }
      });
    }
}
...
componentDidMount() {
    ...
    this._checkForUpdate()
}
...
_checkForUpdates = () => {
  if (this.props.installingUpdate) {
    this.props.dispatch(installingUpdate(false))
    this.props.dispatch(updateReady(false))
    setTimeout(() => {
      this.props.dispatch(openSnackBar({
        message: "The pending update was installed"
      }))
    }, 40);
  } else {
    codePush.checkForUpdate().then(res => {
      if (res) {
        res.download().then(this._handleUpdateAvailable)
      }
    })
  }
}
_handleUpdateAvailable = localPackage => {
  localPackage.install(codePush.InstallMode.IMMEDIATE).then(this._handleUpdateInstalled)
}
_handleUpdateInstalled = res => {
  this.props.dispatch(updateReady(true))
}
_installUpdate = () => {
  try {
    this.props.dispatch(installingUpdate(true))
    setTimeout(() => {
      const reduxStore = store.getState()
      AsyncStorage.setItem('appState', JSON.stringify(reduxStore));
      codePush.allowRestart();
      // codePush.restartApp()
    }, 40);
  } catch(e) {
    console.log(e)
  }
}

所有这些操作将在后台下载更新,并准备好在菜单中显示一个“更新”按钮,当按下该按钮时,它将调用_installUpdate

我要保存当前的Redux存储,以便在重启完成后将Redux存储应用回应用程序,就像最终用户什么都没发生。

在实际的android文件中,我有它所需要的确切设置,如果需要可以添加,但我不相信。

给我的印象是我不需要调用notifyAppReady(),因为我使用HOC来包装我的主要应用程序组件,是这样吗?出于价值考虑,我尝试在启动我的应用的各种不同地方添加该方法,但仍然无法正常工作。

0 个答案:

没有答案