import { NativeModules, Platform } from 'react-native'; const LINKING_ERROR = `The package 'react-native-inapp-update' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n'; const InappUpdate = NativeModules.InappUpdate ? NativeModules.InappUpdate : new Proxy( {}, { get() { throw new Error(LINKING_ERROR); }, } ); // type appUpdateType = 'IMMEDIATE' | 'FLEXIBLE'; /** *@returns {Promise} */ export function checkisUpdateAvailable(): Promise { return InappUpdate.checkUpdateStatus(); } /** * @param {appUpdateType} appUpdateType * @param {string} clientVersionStalenessDays * @returns {Promise} * */ export function startUpdate( appUpdateType: appUpdateType, clientVersionStalenessDays?: number ): Promise { return InappUpdate.checkAppUpdate( appUpdateType === 'FLEXIBLE' ? 0 : 1, !!clientVersionStalenessDays ? clientVersionStalenessDays : 0 ); } /** * @return {promise} */ export function onCompleteUpdate(): Promise { return InappUpdate.completeUpdate(); }