AppState.addEventListener('change', (newState) => { if (newState === 'active') { codePush.sync({ installMode: InstallMode.IMMEDIATE, }); // {installMode: InstallMode.ON_NEXT_RESTART} } });
export function callCodePush(){ //隐式更新 codePush.sync(); /* let updateDialogOptions = { title: "更新提示", optionalUpdateMessage: "检测到可用的新版本,是否升级?", optionalIgnoreButtonLabel: "无视", optionalInstallButtonLabel: "升级", }; //显式更新 codePush.sync( { updateDialog: updateDialogOptions }, (status)=>{ if (status == codePush.SyncStatus.INSTALLING_UPDATE) { } } ); */ }
/** Update pops a confirmation dialog, and then immediately reboots the app */ syncImmediate() { CodePush.sync( { installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true }, this.codePushStatusDidChange.bind(this), this.codePushDownloadDidProgress.bind(this) ); }
export default function updateCheck() { codePush.sync({ deploymentKey: '43ENH2WbHU9EgYYtD7ofoMR7qRwNE1M-WAV0l', updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE }); }
updateDemo() { const onSyncStatusChange = (syncStatus) => { if (syncStatus !== 5) { this.setState({ animating: false, }); } switch (syncStatus) { case 0: Alert.alert(null, '最新版本'); break; case 3: Alert.alert(null, '发生错误'); break; default: break; } }; const onError = function (error) { this.setState({ animating: false, }); Alert.alert(null, `发生错误: ${error}`); }; codePush.sync({ updateDialog: { updateTitle: '检测有更新', optionalUpdateMessage: 'demo app 有新版本,是否安装?', optionalIgnoreButtonLabel: 'No', optionalInstallButtonLabel: 'Yes', }, installMode: codePush.InstallMode.IMMEDIATE, }, onSyncStatusChange, null, onError); }
/** Update is downloaded silently, and applied on restart (recommended) */ sync() { CodePush.sync( {}, this.codePushStatusDidChange.bind(this), this.codePushDownloadDidProgress.bind(this) ); }
async _updateFromCodePush(){ const self = this try{ return await CodePush.sync({ installMode: CodePush.InstallMode.IMMEDIATE, },syncStatus=>{ switch(syncStatus) { case CodePush.SyncStatus.CHECKING_FOR_UPDATE: self.setState({ syncMessage: "检查更新中..." }); break; case CodePush.SyncStatus.DOWNLOADING_PACKAGE: self.setState({ syncMessage: "更新包下载中..." }); break; case CodePush.SyncStatus.AWAITING_USER_ACTION: self.setState({ syncMessage: "等待中..." }); break; case CodePush.SyncStatus.INSTALLING_UPDATE: self.setState({ syncMessage: "安装更新包..." }); break; case CodePush.SyncStatus.UP_TO_DATE: self.setState({ syncMessage: "已是最新版本", progress: false }); break; case CodePush.SyncStatus.UPDATE_IGNORED: self.setState({ syncMessage: "更新已暂停", progress: false }); break; case CodePush.SyncStatus.UPDATE_INSTALLED: self.setState({ syncMessage: "更新安装成功,下次重启更新生效", progress: false }); break; case CodePush.SyncStatus.UNKNOWN_ERROR: self.setState({ syncMessage: "未知的错误", progress: false }); break; } },progress=>{ this.setState({progress}) }) }catch(e){ CodePush.log(e) this._toast.show("更新服务器异常") } }
_handleAppStateChange(currentAppState) { if(currentAppState === 'active') { CodePush.sync({ installMode: CodePush.InstallMode.ON_NEXT_RESUME }); } }
async componentDidMount() { if(Platform.OS === 'ios' && false) { let result = await codePush.checkForUpdate(); if(result) { codePush.sync({ updateDialog: { title: "发现婚格有更新", optionalUpdateMessage: "小主,app更新啦~快来更新", optionalInstallButtonLabel: "安装", optionalIgnoreButtonLabel: "下次再说", appendReleaseDescription: true, descriptionPrefix: "\n\n本次更新:\n" }, installMode: codePush.InstallMode.IMMEDIATE }, (status) => { switch (status) { case codePush.SyncStatus.DOWNLOADING_PACKAGE: this.setState({ finished: false }); break; case codePush.SyncStatus.INSTALLING_UPDATE: break; case codePush.SyncStatus.UPDATE_INSTALLED: Alert.alert("更新完成", "正在重启"); break; case codePush.SyncStatus.SYNC_IN_PROGRESS: break; } }, (progress) => { this.setState({ progress }); }); } } }
componentDidMount() { // this.setState({initialLoad: false}); // eslint-disable-line AsyncStorage.getItem(STORAGE_KEY).then((data) => { console.log(STORAGE_KEY); this.setState({initialLoad: false}); // eslint-disable-line if (data) { const {hostname, apiKey} = JSON.parse(data); apiActions.setHostname(hostname); apiActions.setApiKey(apiKey); this.setState({keyFound: true}); } }); codePush.sync({ installMode: InstallMode.IMMEDIATE, }); // Check for CodePush updates when app becomes active. AppState.addEventListener('change', (newState) => { if (newState === 'active') { codePush.sync({ installMode: InstallMode.IMMEDIATE, }); // {installMode: InstallMode.ON_NEXT_RESTART} } }); }
InteractionManager.runAfterInteractions(() => { CodePush.sync({}, (status) => { if (status === CodePush.SyncStatus.UPDATE_INSTALLED) { CodePush.restartApp(); } }); });
handleAppStateChange(appState) { if (appState === 'active') { CodePush.sync({ installMode: CodePush.InstallMode.ON_NEXT_RESUME, minimumBackgroundDuration: 60 * 5, }); } }
componentDidMount() { AppState.addEventListener('change', this.handleAppStateChange); CodePush.sync({ installMode: CodePush.InstallMode.ON_NEXT_RESUME, minimumBackgroundDuration: 60 * 5, }); Linking.addEventListener('url', this.handleOpenURL); }
componentDidMount() { // 首次启动时检查时候有更新 CodePush.sync({ installMode: CodePush.InstallMode.ON_NEXT_RESUME }); AppState.addEventListener('change', this._handleAppStateChange.bind(this)); }
handleAppStateChange: function(appState) { if (appState === 'active') { this.props.dispatch(loadSessions()); this.props.dispatch(loadNotifications()); this.props.dispatch(loadSurveys()); CodePush.sync({installMode: CodePush.InstallMode.ON_NEXT_RESUME}); } },
AppState.addEventListener('change', currentAppState => { if (currentAppState === 'active') { codePush.sync({installMode: codePush.InstallMode.ON_NEXT_RESUME}); this.refresh(); this.startAutoUpdate(); } else if (currentAppState === 'background' && this.updateInterval) { this.stopAutoUpdate(); } });
componentDidMount() { CodePush.notifyApplicationReady(); CodePush.sync({ deploymentKey: "VlOQwXQYJIeh667505A-PYkc4RoT4JVuG2y8W", updateDialog: true, //installMode: CodePush.InstallMode.ON_NEXT_RESUME installMode: CodePush.InstallMode.IMMEDIATE }); alert("I'm CodePush.notifyApplicationReady();"); }
componentDidMount() { codePush.sync({ updateDialog: { updateTitle: '检测有更新', optionalUpdateMessage: 'demo app 有新版本,是否安装?', optionalIgnoreButtonLabel: 'No', optionalInstallButtonLabel: 'Yes', }, }); }
componentWillMount() { CodePush.sync({ deploymentKey: 'm-riu3kK1__kGboK4WPIwBYs7ZwzEygDCEa5e', updateDialog: { optionalIgnoreButtonLabel: '稍后', optionalInstallButtonLabel: '后台更新', optionalUpdateMessage: '是否更新?---', title: '更新提示' }, installMode: CodePush.InstallMode.IMMEDIATE }); }
componentWillMount() { if (Platform.OS == 'ios') { codePush.sync(); } this.popupListener = NativeAppEventEmitter.addListener('showPopup', (options) => { this.global_popup.tip({ title: options.title, content: options.content, btn: { text: options.buttonText }, }); }); }
componentDidMount() { CodePush.sync({ deploymentKey: "RGOUfyINiLicZnld67aD0nrbRvyLV1Ifekvul", updateDialog: { optionalIgnoreButtonLabel: '稍后', optionalInstallButtonLabel: '后台更新', optionalUpdateMessage: 'Reading有新版本了,是否更新?', title: '更新提示' }, installMode: CodePush.InstallMode.ON_NEXT_RESTART }); AV.initialize('Tfi1z7dN9sjMwSul8sYaTEvg-gzGzoHsz', '57qmeEJonefntNqRe17dAgi4'); }
componentDidMount: function() { AppState.addEventListener('change', this.handleAppStateChange); // TODO: Make this list smaller, we basically download the whole internet this.props.dispatch(loadNotifications()); this.props.dispatch(loadMaps()); this.props.dispatch(loadConfig()); this.props.dispatch(loadSessions()); this.props.dispatch(loadFriendsSchedules()); this.props.dispatch(loadSurveys()); updateInstallation({version}); CodePush.sync({installMode: CodePush.InstallMode.ON_NEXT_RESUME}); },
componentDidMount () { //android注册返回事件 BackAndroid.addEventListener('hardwareBackPress', ()=> { var iLength=this.refs.navigator.getCurrentRoutes().length; if (iLength>1) { this.refs.navigator.pop(); return true; } return false; }); codePush.sync(); }
componentDidMount() { codePush.sync({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE }, (status) => { switch (status) { case codePush.SyncStatus.DOWNLOADING_PACKAGE: this.setState({status: 'Downloading'}); break; case codePush.SyncStatus.INSTALLING_UPDATE: this.setState({status: 'Installing'}); break; } }, ({ receivedBytes, totalBytes, }) => { this.setState({receivedBytes, totalBytes}); } ); }
_handleAppStateChange(newState){ newState === "active" && codePush.sync(); }
componentDidMount() { CodePush.sync(); }
shouldSync().done((shouldSync)=>shouldSync && codePush.sync());
componentWillMount() { codePush.sync( { updateDialog: {appendReleaseDescription: true, title: 'An update is available!', optionalIgnoreButtonLabel: 'Not Now', descriptionPrefix: '\nChangelog: \n'}, installMode: codePush.InstallMode.IMMEDIATE }); }
updateBundleByCodePush() { let self = this; CodePush.sync({ updateDialog: {// update dialogue appendReleaseDescription: true, descriptionPrefix: Strings.updateDescription, // description mandatoryContinueButtonLabel: Strings.update, // mandatory continue mandatoryUpdateMessage: Strings.mandatoryUpdate, // mandatory message optionalUpdateMessage: Strings.optionalUpdate, // optional message optionalInstallButtonLabel: Strings.update, // optional install label optionalIgnoreButtonLabel: Strings.ignore, // optional ignore label title: Strings.update, // title }, // install mode installMode: CodePush.InstallMode.IMMEDIATE }, (status) => { // all status des here https://github.com/Microsoft/react-native-code-push#syncstatus console.log('CodePush status = ' + status); switch (status) { case CodePush.SyncStatus.DOWNLOADING_PACKAGE: //2 // Show "downloading" modal console.log("CodePush Downloading package."); self.setState({ updateDlgContent: self.getCodePushUpdateDlg() }); self.setUpdateDlgActive(true); break; case CodePush.SyncStatus.INSTALLING_UPDATE: //3 // Hide "downloading" modal console.log("CodePush Installing update."); self.setUpdateDlgActive(false); break; case CodePush.SyncStatus.CHECKING_FOR_UPDATE: //0 console.log("CodePush Checking for updates."); break; case CodePush.SyncStatus.UP_TO_DATE: //4 console.log("CodePush up to date."); break; case CodePush.SyncStatus.UPDATE_IGNORED: //5 console.log("CodePush ignore update."); break; case CodePush.SyncStatus.UPDATE_INSTALLED: //6 console.log("CodePush update installed."); break; case CodePush.SyncStatus.UNKNOWN_ERROR: //-1 console.log("CodePush unknown error."); break; } }, ({ receivedBytes, totalBytes, }) => { self.setState({ // receive bytes from server updateDlgContent: self.getCodePushUpdateDlg(), updateReceived: receivedBytes, updateTotal: totalBytes, }); console.log("receivedBytes, totalBytes:" + receivedBytes + ", " + totalBytes); } ); }
componentDidMount(){ codePush.sync({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE }); }