Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Author: 墨子
* GitHub: https://github.com/duheng/Mozi
* Email: duheng1100@163.com
*/
import React, { Component, } from 'react';
import { Provider, } from 'react-redux';
import SplashScreen from 'react-native-splash-screen';
import codePush from 'react-native-code-push';
import configureStore from './app/store/configureStore';
import App from './AppNavigationState';
const store = configureStore();
@codePush({
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
installMode: codePush.InstallMode.ON_NEXT_SUSPEND,
})
export default class Root extends Component {
componentDidMount() {
SplashScreen.hide(); // 隐藏启动屏
}
render() {
console.log('store----', store);
return (
);
}
}
componentDidMount() {
CodePush.checkForUpdate()
.then( (update) =>{
if( !update ){
Alert.alert("app是最新版了");
}else {
Alert.alert("有更新哦");
}
});
CodePush.sync({ updateDialog: true, installMode: CodePush.InstallMode.IMMEDIATE },
(status) => {
switch (status) {
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
// this.setState({showDownloadingModal: true});
// this.refs.modal.open();
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
// this.setState({showInstalling: true});
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
// this.refs.modal.close();
// this.setState({showDownloadingModal: false});
break;
}
},
({ receivedBytes, totalBytes, }) => {
update.download(CheckCodePushUpdateUtil.down).then(instance => {
//下载完成了,调用这个方法
console.log("开始安装");
instance.install(codePush.InstallMode.IMMEDIATE).then(() => {
console.log("安装完成");
codePush.notifyAppReady();
codePush.allowRestart();
codePush.restartApp(true);
}).catch(reason => {
CheckCodePushUpdateUtil.error();
});
}).catch((reason) => {
CheckCodePushUpdateUtil.error();
const syncOnNextRestart = () => {
console.info('[CodePush]syncOnNextSuspend: 安装更新,但不立马重启,直到下一次重新进入')
CodePush.sync({ installMode: CodePush.InstallMode.ON_NEXT_RESTART }, codePushStatusDidChange)
}
import { useEffect } from 'react';
import codePush from 'react-native-code-push';
const codePushOptions = {
installMode: codePush.InstallMode.ON_NEXT_RESUME,
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
};
const CodePushComponent = () => {
useEffect(() => {
codePush.sync();
}, []);
return null;
};
export default codePush(codePushOptions)(CodePushComponent);
onButtonPress() {
codePush.sync({
updateDialog: true,
installMode: codePush.InstallMode.IMMEDIATE
});
}
_syncUpdata = () => {
codePush.sync({
updateDialog: true,
installMode: codePush.InstallMode.ON_NEXT_RESTART
});
}
syncImmediate() {
CodePush.sync(
{ installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true },
this.codePushStatusDidChange.bind(this),
this.codePushDownloadDidProgress.bind(this)
);
}
update () {
codePush.sync({
updateDialog: {
title: '更新',
appendReleaseDescription: true,
descriptionPrefix: '更新内容:\n',
mandatoryContinueButtonLabel: '更新',
mandatoryUpdateMessage: '',
optionalIgnoreButtonLabel: '忽略',
optionalInstallButtonLabel: '更新',
optionalUpdateMessage: '',
},
mandatoryInstallMode: codePush.InstallMode.IMMEDIATE,
})
}
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
import React from 'react';
import {
AppRegistry
} from 'react-native';
import Root from './src/redux/root'
import CodePush from 'react-native-code-push'
const app = CodePush({
installMode: CodePush.InstallMode.IMMEDIATE,
updateDialog: true
})(Root)
AppRegistry.registerComponent('SimpleApp', ()=>app);