sync

Tags
추가설명
 
 
SyncOptions 타입이 코드푸시 설정할 때인 CodePushOptions랑, sync 메소드를 호출 할 때 두 곳에서 사용되고 있다.
 
export interface CodePushOptions extends SyncOptions { /** * Specifies when you would like to synchronize updates with the CodePush server. * Defaults to codePush.CheckFrequency.ON_APP_START. */ checkFrequency: CodePush.CheckFrequency; }
CheckFrequency 타입
💡
우리는 코드푸시 체크를 진행하는 화면이 별도로 있으므로, MANUAL로 설정하고, 코드푸시 업데이트 체크가 필요한 상황에 커스텀한 코드푸시 업데이트 화면으로 이동시킨 후 매뉴얼하게 sync 메소드를 호출하여 코드푸시 업데이트를 진행시키도록 한다.
enum CheckFrequency { /** * When the app is fully initialized (or more specifically, when the root component is mounted). */ ON_APP_START, /** * When the app re-enters the foreground. */ ON_APP_RESUME, /** * Don't automatically check for updates, but only do it when codePush.sync() is manully called inside app code. */ MANUAL }
 
/** * Allows checking for an update, downloading it and installing it, all with a single call. * * @param options Options used to configure the end-user update experience (e.g. show an prompt?, install the update immediately?). * @param syncStatusChangedCallback An optional callback that allows tracking the status of the sync operation, as opposed to simply checking the resolved state via the returned Promise. * @param downloadProgressCallback An optional callback that allows tracking the progress of an update while it is being downloaded. * @param handleBinaryVersionMismatchCallback An optional callback for handling target binary version mismatch */ function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DownloadProgressCallback, handleBinaryVersionMismatchCallback?: HandleBinaryVersionMismatchCallback): Promise<SyncStatus>;
 
SyncOptions 타입
export interface SyncOptions { /** * Specifies the deployment key you want to query for an update against. By default, this value is derived from the Info.plist * file (iOS) and MainActivity.java file (Android), but this option allows you to override it from the script-side if you need to * dynamically use a different deployment for a specific call to sync. */ deploymentKey?: string; /** * Specifies when you would like to install optional updates (i.e. those that aren't marked as mandatory). * Defaults to codePush.InstallMode.ON_NEXT_RESTART. */ installMode?: CodePush.InstallMode; /** * Specifies when you would like to install updates which are marked as mandatory. * Defaults to codePush.InstallMode.IMMEDIATE. */ mandatoryInstallMode?: CodePush.InstallMode; /** * Specifies the minimum number of seconds that the app needs to have been in the background before restarting the app. This property * only applies to updates which are installed using `InstallMode.ON_NEXT_RESUME` or `InstallMode.ON_NEXT_SUSPEND`, and can be useful * for getting your update in front of end users sooner, without being too obtrusive. Defaults to `0`, which has the effect of applying * the update immediately after a resume or unless the app suspension is long enough to not matter, regardless how long it was in the background. */ minimumBackgroundDuration?: number; /** * An "options" object used to determine whether a confirmation dialog should be displayed to the end user when an update is available, * and if so, what strings to use. Defaults to null, which has the effect of disabling the dialog completely. Setting this to any truthy * value will enable the dialog with the default strings, and passing an object to this parameter allows enabling the dialog as well as * overriding one or more of the default strings. */ updateDialog?: UpdateDialog; /** * The rollback retry mechanism allows the application to attempt to reinstall an update that was previously rolled back (with the restrictions * specified in the options). It is an "options" object used to determine whether a rollback retry should occur, and if so, what settings to use * for the rollback retry. This defaults to null, which has the effect of disabling the retry mechanism. Setting this to any truthy value will enable * the retry mechanism with the default settings, and passing an object to this parameter allows enabling the rollback retry as well as overriding * one or more of the default values. */ rollbackRetryOptions?: RollbackRetryOptions; }
 
InstallMode 타입
옵셔널 업데이트인 installMode와, 필수 업데이트인 mandatoryInstallMode를 설정할 때 사용함
enum InstallMode { /** * Indicates that you want to install the update and restart the app immediately. * 업데이트 설치 뿐만 아니라, 업데이트 적용을 위한 앱 재시작까지 해줌 */ IMMEDIATE, /** * Indicates that you want to install the update, but not forcibly restart the app. */ ON_NEXT_RESTART, /** * Indicates that you want to install the update, but don't want to restart the app until the next time * the end user resumes it from the background. This way, you don't disrupt their current session, * but you can get the update in front of them sooner then having to wait for the next natural restart. * This value is appropriate for silent installs that can be applied on resume in a non-invasive way. */ ON_NEXT_RESUME, /** * Indicates that you want to install the update when the app is in the background, * but only after it has been in the background for "minimumBackgroundDuration" seconds (0 by default), * so that user context isn't lost unless the app suspension is long enough to not matter. * 앱이 백그라운드에 있을 때 업데이트를 설치하고 싶지만 "최소 백그라운드 기간"(기본적으로 0) 동안 백그라운드에 있었던 후에만 업데이트를 설치하여 앱 일시 중단이 중요하지 않을 정도로 길지 않은 경우 사용자 컨텍스트가 손실되지 않도록 함을 나타냅니다. */ ON_NEXT_SUSPEND }
⚠️
디바이스 앱의 경우 앱이 처음 켜진 후에는 백그라운드로 전환될 일이 없다. 따라서 IMMEDIATE 만이 유일한 옵션임.
 
 
UpdateDialog 타입 (TBD)
export interface UpdateDialog { /** * Indicates whether you would like to append the description of an available release to the * notification message which is displayed to the end user. Defaults to false. */ appendReleaseDescription?: boolean; /** * Indicates the string you would like to prefix the release description with, if any, when * displaying the update notification to the end user. Defaults to " Description: " */ descriptionPrefix?: string; /** * The text to use for the button the end user must press in order to install a mandatory update. Defaults to "Continue". */ mandatoryContinueButtonLabel?: string; /** * The text used as the body of an update notification, when the update is specified as mandatory. * Defaults to "An update is available that must be installed.". */ mandatoryUpdateMessage?: string; /** * The text to use for the button the end user can press in order to ignore an optional update that is available. Defaults to "Ignore". */ optionalIgnoreButtonLabel?: string; /** * The text to use for the button the end user can press in order to install an optional update. Defaults to "Install". */ optionalInstallButtonLabel?: string; /** * The text used as the body of an update notification, when the update is optional. Defaults to "An update is available. Would you like to install it?". */ optionalUpdateMessage?: string; /** * The text used as the header of an update notification that is displayed to the end user. Defaults to "Update available". */ title?: string; }
 
RollbackRetryOptions 타입
💡
rollbackRetryOptionsnull을 넣으면 재시도를 하지 않도록 처리를 할 수 있다
🗣
롤백 이후 대기시간이 있는 이유가 뭘까? 롤백이 발생할 경우 갖고 있던 안정적인 마지막 버전으로 로컬에서 롤백이 진행되어 정상 동작중임이 보장되는 상황으로 인지하기 때문이다. 따라서 반드시 최신 업데이트로 업데이트 해야한다는게 급박하지 않은 상황이라면 디폴트 설정도 유의미한 설정이 될 수 있다.
export interface RollbackRetryOptions { /** * Specifies the minimum time in hours that the app will wait after the latest rollback * before attempting to reinstall same rolled-back package. Defaults to `24`. * 마지막 롤백 후 동일한 롤백 패키지를 다시 설치하기 전에 앱이 대기할 최소 시간(시간)을 지정합니다. 기본값은 24입니다. * 설정 값을 0이나 분 단위로도 설정할 수 있다. */ delayInHours?: number; /** * Specifies the maximum number of retry attempts that the app can make before it stops trying. * Cannot be less than `1`. Defaults to `1`. */ maxRetryAttempts?: number; }
 
 
sync 메소드에서 다루는 콜백 3가지
export type DownloadProgressCallback = (progress: DownloadProgress) => void; export type SyncStatusChangedCallback = (status: CodePush.SyncStatus) => void; export type HandleBinaryVersionMismatchCallback = (update: RemotePackage) => void;
 
SyncStatus 타입
enum SyncStatus { /** * The app is up-to-date with the CodePush server. * 서버의 최신 버전과 동일한 상태 */ UP_TO_DATE, /** * An available update has been installed and will be run either immediately after the * syncStatusChangedCallback function returns or the next time the app resumes/restarts, * depending on the InstallMode specified in SyncOptions * 사용 가능한 업데이트가 설치되었으며 SyncOptions에 명시한 InstallMode에 따라, syncStatusChangedCallback 콜백이 호출된 직후 바로 업데이트를 하던지 혹은 앱 재시작 등 정책 이후에 실행하던지 한다.. * 즉, 업데이트 다운로드 및 설치까지 정상 완료하였고, 설정한 정책에 따른 적용을 위한 시기를 기다리는 상태. */ UPDATE_INSTALLED, /** * The app had an optional update which the end user chose to ignore. * (This is only applicable when the updateDialog is used) * 옵셔널한 업데이트 버전이며, 사용자가 업데이트를 거부한 경우 (mandatory 버전은 사용자가 거부할 수 없음) */ UPDATE_IGNORED, /** * The sync operation encountered an unknown error. */ UNKNOWN_ERROR, /** * There is an ongoing sync operation running which prevents the current call from being executed. */ SYNC_IN_PROGRESS, /** * The CodePush server is being queried for an update. */ CHECKING_FOR_UPDATE, /** * An update is available, and a confirmation dialog was shown * to the end user. (This is only applicable when the updateDialog is used) */ AWAITING_USER_ACTION, /** * An available update is being downloaded from the CodePush server. */ DOWNLOADING_PACKAGE, /** * An available update was downloaded and is about to be installed. * 업데이트 다운로드는 완료하였고, 설치 하려고 하는 중 */ INSTALLING_UPDATE }
💡
업데이트 설치(다운로드)를 하는 것과, 적용 하는 것이 별개의 과정임을 인지한다.
💡
업데이트 시도 시 상태변화 플로우 # 업데이트가 있어서 시도할 때
LOG CHECKING_FOR_UPDATE LOG DOWNLOADING_PACKAGE LOG INSTALLING_UPDATE LOG UPDATE_INSTALLED # 업데이트 설치 완료 후, 적용 위해 새로 켰을 때
LOG CHECKING_FOR_UPDATE LOG [CodePush] Reporting CodePush update success (v218) LOG UP_TO_DATE
 
# 업데이트가 이미 진행중인데, metro에서 저장 눌렀을 경우
LOG  SYNC_IN_PROGRESS
LOG update 있나요? {"appVersion": "2.0.10", "deploymentKey": "<코드푸시 키>", "description": undefined, "download": [Function download], "downloadUrl": "https://codepush-secondary.blob.core.windows.net/storagev2/<번들 URL>", "failedInstall": false, "isMandatory": true, "isPending": false, "label": "v3", "packageHash": "<패키지 해시값>", "packageSize": 1638983}
SYNC_IN_PROGRESS는 언제 설정되는 거지??
 

코드푸시 클래스 메소드

/** * Clear all downloaded CodePush updates. * This is useful when switching to a different deployment which may have an older release than the current package. * Note: we don’t recommend to use this method in scenarios other than that (CodePush will call * this method automatically when needed in other cases) as it could lead to unpredictable behavior. */ function clearUpdates(): void;