Command palette

@yasinsensoy/native

React Native · APIs and utilities

Store updates

In-app update.

7 exports

Import

import { AppUpdate, useAppUpdate } from "@yasinsensoy/native";

AppUpdate

module

In-app update.

  • Android (Google Play In-App Updates): immediate is Play's fullscreen flow (downloads, installs, restarts the app); flexible downloads in the background, then AppUpdate.complete installs and restarts. Works only in apps installed from the Play Store (for testing, use an internal test track in the Play Console).
  • iOS: Apple does not allow installing from inside the app. AppUpdate.check queries the version on the App Store; AppUpdate.start opens the App Store page inside the app (the user taps "Update"). App Store version info may lag a few hours after release.
NameTypeDescription
check(options?: { country?: string; }) => Promise<AppUpdateInfo>Is there an update. iOS: country is the App Store country (default: the device's).
start(options?: { type?: "immediate" | "flexible"; }) => Promise<AppUpdateResult>Starts the update. Android: immediate (default) or flexible. iOS always opens the App Store page. accepted if the user accepted, dismissed if they declined.
complete() => Promise<void>Android flexible: installs the downloaded update (the app restarts).
openStore() => Promise<void>Opens the store page (inside the app on iOS).
addProgressListener(listener: (progress: AppUpdateProgress) => void) => () => voidAndroid flexible download progress.

useAppUpdate

function

Checks for an update on mount (and with checkOnMount); tracks flexible download progress.

useAppUpdate({ checkOnMount, }?: { checkOnMount?: boolean; }): UseAppUpdateResult

Examples

const update = useAppUpdate();
if (update.info?.available) return <Button onPress={() => update.start()}>Update</Button>;
if (update.progress?.status === "downloaded") return <Button onPress={update.complete}>Restart</Button>;

AppUpdateInfo

interface

Update info.

NameTypeDescription
availablebooleanA newer version is available in the store.
inProgressbooleanAndroid: a started update is in progress (e.g. an immediate one was interrupted).
currentVersionstring | nullInstalled version.
storeVersionstring | nulliOS: version on the App Store. Android Play does not provide it (null).
versionCodenumber | nullAndroid: version code in the store.
stalenessDaysnumber | nullHow many days the update has been waiting (Android Play; on iOS since the release date).
prioritynumber | nullAndroid: priority set in the Play Console (0–5).
immediateAllowedbooleanFullscreen update available (iOS: App Store page).
flexibleAllowedbooleanAndroid: background download available.
installStatusAppUpdateStatusAndroid: status of the ongoing download/install.
storeUrlstring | nullStore page.
releaseNotesstring | nulliOS: "What's New" text.

Download/install status (Android flexible).

type AppUpdateStatus = "unknown" | "pending" | "downloading" | "downloaded" | "installing" | "installed" | "failed" | "canceled"

Download progress (Android flexible).

NameTypeDescription
statusAppUpdateStatusCurrent phase of the update.
loadednumberBytes downloaded so far.
totalnumberTotal bytes to download (0 if unknown).
errornumber | nullError code (Play InstallErrorCode).

Result of starting the update.

type AppUpdateResult = "accepted" | "dismissed"

Result of useAppUpdate.

NameTypeDescription
infoAppUpdateInfo | nullLast check (null if not checked).
progressAppUpdateProgress | nullAndroid flexible progress.
errorError | nullCheck error (no Play Store, network…).
check(): Promise<AppUpdateInfo | null>Checks again.
start(type?: "immediate" | "flexible"): Promise<AppUpdateResult | null>Starts the update.
complete(): Promise<void>Installs the downloaded update (Android flexible).