728x90
반응형
App.tsx 에서 progress / message 받아서 사용
OTA 방식처러 보인다
직접 작성한 코드라 변경하셔서 사용하십셔
import { useEffect, useState } from 'react';
import CodePush, { DownloadProgress } from 'react-native-code-push';
const codePushOptions = {
checkFrequency: CodePush.CheckFrequency.ON_APP_START,
// 추후 업로드 시, 업데이트 알림 띄우는 용도
updateDialog: {
title: '...',
optionalUpdateMessage: '...',
optionalInstallButtonLabel: '업데이트',
optionalIgnoreButtonLabel: '아니요.',
},
installMode: CodePush.InstallMode.IMMEDIATE,
};
export const useCodePush = () => {
const [progress, setProgress] = useState<DownloadProgress | boolean>(true);
const [message, setMessage] = useState<string>('Checking for update');
const codePushStatusDidChange = (syncStatus: CodePush.SyncStatus) => {
switch (syncStatus) {
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
console.log('[CodePush] Checking for update.');
setMessage('Checking for update.');
break;
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
console.log('[CodePush] Downloading package.');
setMessage('Downloading package.');
break;
case CodePush.SyncStatus.AWAITING_USER_ACTION:
console.log('[CodePush] Awaiting user action.');
setMessage('Awaiting user action.');
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
console.log('[CodePush] Installing update.');
setMessage('Installing update.');
break;
case CodePush.SyncStatus.UP_TO_DATE:
console.log('[CodePush] App up to date.');
setMessage('App up to date.');
setProgress(false);
break;
case CodePush.SyncStatus.UPDATE_IGNORED:
console.log('[CodePush] Update cancelled by user.');
setMessage('Update cancelled by user.');
setProgress(false);
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
console.log(
'[CodePush] Update installed and will be applied on restart.',
);
setMessage('Update installed and will be applied on restart.');
setProgress(false);
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
console.log('An unknown error occurred.');
setMessage('An unknown error occurred.');
setProgress(false);
break;
}
};
const codePushDownloadDidProgress = (progress: DownloadProgress) => {
console.log('codePushDownloadDidProgress ::: ' + JSON.stringify(progress));
};
useEffect(() => {
const syncCodePushImmediate = async () => {
try {
const result = await CodePush.sync(
codePushOptions,
codePushStatusDidChange,
codePushDownloadDidProgress,
);
console.log('result :::::' + result);
} catch (error) {
console.log('syncCodePushImmediate error ::::;' + error);
}
};
syncCodePushImmediate();
}, []);
return { progress, message };
};
728x90
반응형