Reference version

Expo 更新 iconExpo 更新

一个使你的应用能够管理对应用代码的远程更新的库。

Android
iOS
tvOS
Included in Expo Go
Bundled version:
~0.28.17

For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.

expo-updates 是一个库,可让你的应用管理对应用代码的远程更新。它会与已配置的远程更新服务通信,以获取可用更新的信息。

安装

expo-updates 库可以通过 EAS Update 自动配置,EAS Update 是一个托管服务,用于管理并向你的应用提供更新。要开始使用 EAS Update,请按照 快速开始 指南中的说明进行操作。

另外,在需要其他远程更新服务,或者配置仅在原生文件中指定的情况下,也可以手动配置 expo-updates 库。

手动安装、配置和自定义远程更新服务
Terminal
npx expo install expo-updates

如果你要在 bare React Native app 中安装此库,或者在使用手动配置原生代码的通用应用中安装,请遵循这些 安装说明

如果使用 应用配置 进行配置,则至少可以通过设置以下应用配置属性来配置此库:

远程服务必须实现 Expo Updates 协议EAS Update 就是这样一种服务,但也可以将此库与自定义服务器一起使用。

自定义 Expo Updates 服务器

自定义服务器及使用该服务器的应用示例实现

配置

有一些构建时配置选项会控制该库的行为。对于大多数应用,这些配置值都在 应用配置 中的 updates 属性下设置。

应用配置属性默认值是否必需?iOS plist/dictionary 键Android 元数据名称Android Map 键
updates.enabledtrueEXUpdatesEnabledexpo.modules.updates.ENABLEDenabled
updates.url(无)EXUpdatesURLexpo.modules.updates.EXPO_UPDATE_URLupdateUrl
updates.requestHeaders(无)EXUpdatesRequestHeadersexpo.modules.updates.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEYrequestHeaders
runtimeVersion(无)EXUpdatesRuntimeVersionexpo.modules.updates.EXPO_RUNTIME_VERSIONruntimeVersion
updates.checkAutomaticallyALWAYSEXUpdatesCheckOnLaunchexpo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCHcheckOnLaunch
updates.fallbackToCacheTimeout0EXUpdatesLaunchWaitMsexpo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MSlaunchWaitMs
updates.useEmbeddedUpdatetrueEXUpdatesHasEmbeddedUpdateexpo.modules.updates.HAS_EMBEDDED_UPDATEhasEmbeddedUpdate
updates.codeSigningCertificate(无)EXUpdatesCodeSigningCertificateexpo.modules.updates.CODE_SIGNING_CERTIFICATEcodeSigningCertificate
updates.codeSigningMetadata(无)EXUpdatesCodeSigningMetadataexpo.modules.updates.CODE_SIGNING_METADATAcodeSigningMetadata
updates.assetPatternsToBeBundled(无)N/AN/AN/A
updates.disableAntiBrickingMeasuresfalseEXUpdatesDisableAntiBrickingMeasuresexpo.modules.updates. DISABLE_ANTI_BRICKING_MEASURESdisableAntiBrickingMeasures

两个核心必需的配置选项是:

按照 EAS Update 的 快速开始 指南时,这些会自动配置。

运行时版本

每次为你的应用构建二进制文件时,它都包含构建时的原生代码和配置以及原生配置,这种独特组合会被表示为一个称为运行时版本的字符串。远程更新会针对某一个运行时版本,这意味着只有运行时版本匹配的二进制文件才能加载该远程更新。

手动配置

可以通过在配置字段中设置字符串值来手动管理运行时版本。

{ "expo": { "runtimeVersion": "<runtime_version_string>" } }
使用运行时版本策略自动配置

运行时版本策略会从项目中已经存在的另一项信息推导出运行时版本。可以在 runtimeVersion 配置字段中按如下方式设置:

{ "expo": { "runtimeVersion": { "policy": "<policy_name>" } } }

可用的策略类型:

appVersion

"appVersion" 策略适用于希望基于应用版本来定义运行时兼容性的项目。

例如,在一个应用配置包含以下内容的项目中:

{ "expo": { "runtimeVersion": { "policy": "appVersion" }, "version": "1.0.0", "ios": { "buildNumber": "1" }, "android": { "versionCode": 1 } } }

"appVersion" 策略会将运行时版本设置为项目当前的 "version" 属性。在这种情况下,Android 和 iOS 构建以及任何更新的运行时版本都会是 "1.0.0"

此策略非常适合包含自定义原生代码,并在每次公开发布后更新 "version" 字段的项目。为了提交应用,应用商店要求每个提交的构建都有更新的原生版本号,因此如果你想确保用户设备上安装的每个版本都有不同的运行时版本,这种策略会很方便。

使用此策略时,每次公开发布都需要手动更新应用配置中的 "version" 字段,但对于 Play Store 的 Internal Test Track 和 App Store 的 TestFlight 上传,你可以依赖 eas.json 中的 "autoIncrement" 选项来 替你管理版本

nativeVersion

"nativeVersion" 策略适用于希望基于项目当前的 "version""versionCode"(Android)或 "buildNumber"(iOS)属性来定义运行时兼容性的项目。

例如,在一个应用配置包含以下内容的项目中:

{ "expo": { "runtimeVersion": { "policy": "nativeVersion" }, "version": "1.0.0", "ios": { "buildNumber": "1" }, "android": { "versionCode": 1 } } }

Android 和 iOS 构建以及任何更新的运行时版本都会是 "[version]([buildNumber|versionCode])" 的组合,在此例中为 "1.0.0(1)"

此策略非常适合包含自定义原生代码的项目,这类项目会为每次构建更新原生版本号(iOS 使用 "buildNumber",Android 使用 "versionCode")。为了提交应用,应用商店要求每个提交的构建都有更新的原生版本号,因此如果你想确保上传到 Play Store 的 Internal Test Track 和 App Store 的 TestFlight 分发工具的每个应用都有不同的 runtimeVersion,这种策略会很方便。

需要知道的是,此策略要求在每次构建之间手动管理原生版本号。

另外,如果你在 Android 和 iOS 之间选择了不同的原生版本,最终会得到具有不同运行时版本的构建和更新。

fingerprint

"fingerprint" 运行时版本策略会自动为你计算运行时版本,包括 SDK 升级或添加自定义原生代码等变化。

{ "expo": { "runtimeVersion": { "policy": "fingerprint" } } }

此策略既适用于有自定义原生代码的项目,也适用于没有自定义原生代码的项目。它通过在构建和更新期间使用 @expo/fingerprint 包来计算项目的哈希值,从而确定构建与更新的兼容性(也称为运行时)。

原生配置与覆盖

如果你的项目不使用 Continuous Native Generation,这些配置值也可以在应用的原生配置文件中设置,或者在原生代码初始化期间覆盖。

原生配置说明

在 Android 上,这些选项被设置为 AndroidManifest.xml 文件中的 meta-data 标签(如果使用了自动设置,则位于安装过程中添加的标签旁边)。你也可以在运行时使用 UpdatesController.overrideConfiguration() 设置或覆盖它们。

在 iOS 上,这些属性被设置为 Expo.plist 文件中的键。你也可以通过调用 AppController.overrideConfiguration 在运行时设置或覆盖它们。

导入 Swift 生成的头文件以在 Objective-C++ 中使用

如果你的 iOS 原生代码或 AppDelegate.mm 是用 Objective-C++ 编写的,你需要添加以下导入来引用 EXUpdatesAppController 上的方法。这只在运行时覆盖配置时才是必需的。

#import "ExpoModulesCore-Swift.h" #import "EXUpdatesInterface-Swift.h" #import "EXUpdates-Swift.h"

用法

默认情况下,expo-updates 会在应用启动时检查更新。如果有可用更新,它会下载更新,并在应用下次重启时应用该更新。你可以使用上面的 checkAutomaticallyfallbackToCacheTimeout 配置选项来调整这种启动行为。

该库还提供了多种常量,用于检查当前更新,以及用于在应用代码中自定义更新行为的函数(在启动之后)。例如,一种常见的替代用法是在应用启动后手动检查更新,而不是在启动时执行默认检查。

示例:手动检查更新

你可以通过以下步骤将应用配置为手动检查更新:

  1. checkAutomatically 配置值设置为 ON_ERROR_RECOVERYNEVER,以禁用该库默认的启动行为。

  2. 添加以下代码来检查可用更新、下载它们并重新加载:

    App.js
    import { View, Button } from 'react-native'; import * as Updates from 'expo-updates'; function App() { async function onFetchUpdateAsync() { try { const update = await Updates.checkForUpdateAsync(); if (update.isAvailable) { await Updates.fetchUpdateAsync(); await Updates.reloadAsync(); } } catch (error) { // 你也可以添加一个 alert(),以便在获取更新时发生错误的情况下查看错误信息。 alert(`获取最新 Expo 更新时出错:${error}`); } } return ( <View> <Button title="获取更新" onPress={onFetchUpdateAsync} /> </View> ); }

测试

该库中的大多数方法和常量只能在发布构建中使用或测试。在调试构建中,默认行为始终是从开发服务器加载最新的 JavaScript。可以构建一个与你的发布构建具有相同更新行为的调试版本应用。这样的应用不会从你的开发服务器打开最新的 JavaScript — 它会像发布构建一样加载已发布的更新。这对于在应用未连接到开发服务器时调试其行为可能很有用。

要在开发构建中测试更新内容,请运行eas update然后在开发构建中浏览到该更新。请注意,这只是在模拟更新在你的应用中看起来的样子,而且在开发构建中运行时,大多数 Updates API 都不可用。

要在发布构建中测试更新,你可以创建一个 .apk 或一个 模拟器构建,或者使用 npx expo run:android --variant releasenpx expo run:ios --configuration Release 在本地创建发布构建(你不需要将此构建提交到商店进行测试)。完整的 Updates API 在发布构建中可用。

要在 Expo Go 中测试更新内容,请运行eas update然后在 Expo Go 中浏览到该更新。请注意,这只是在模拟更新在你的应用中看起来的样子,而且在 Expo Go 中运行时,大多数 Updates API 都不可用。另外请注意,只支持使用 与 Expo Go 兼容的库 的更新。

API

import * as Updates from 'expo-updates';

Constants

Updates.channel

Android
iOS
tvOS

Type: string | null

The channel name of the current build, if configured for use with EAS Update. null otherwise.

Expo Go and development builds are not set to a specific channel and can run any updates compatible with their native runtime. Therefore, this value will always be null when running an update on Expo Go or a development build.

Updates.checkAutomatically

Android
iOS
tvOS

Type: UpdatesCheckAutomaticallyValue | null

Determines if and when expo-updates checks for and downloads updates automatically on startup.

Updates.createdAt

Android
iOS
tvOS

Type: Date | null

If expo-updates is enabled, this is a Date object representing the creation time of the update that's currently running (whether it was embedded or downloaded at runtime).

In development mode, or any other environment in which expo-updates is disabled, this value is null.

Updates.emergencyLaunchReason

Android
iOS
tvOS

Type: null | string

If isEmergencyLaunch is set to true, this will contain a string error message describing what failed during initialization.

Updates.isEmbeddedLaunch

Android
iOS
tvOS

Type: boolean

This will be true if the currently running update is the one embedded in the build, and not one downloaded from the updates server.

Updates.isEmergencyLaunch

Android
iOS
tvOS

Type: boolean

expo-updates does its very best to always launch monotonically newer versions of your app so you don't need to worry about backwards compatibility when you put out an update. In very rare cases, it's possible that expo-updates may need to fall back to the update that's embedded in the app binary, even after newer updates have been downloaded and run (an "emergency launch"). This boolean will be true if the app is launching under this fallback mechanism and false otherwise. If you are concerned about backwards compatibility of future updates to your app, you can use this constant to provide special behavior for this rare case.

Updates.isEnabled

Android
iOS
tvOS

Type: boolean

Whether expo-updates is enabled. This may be false in a variety of cases including:

  • enabled set to false in configuration
  • missing or invalid URL in configuration
  • missing runtime version or SDK version in configuration
  • error accessing storage on device during initialization

When false, the embedded update is loaded.

Updates.latestContext

Android
iOS
tvOS

Type: UpdatesNativeStateMachineContext

Updates.launchDuration

Android
iOS
tvOS

Type: null | number

Number of milliseconds it took to launch.

Updates.manifest

Android
iOS
tvOS

Type: Partial<Manifest>

If expo-updates is enabled, this is the manifest (or classic manifest) object for the update that's currently running.

In development mode, or any other environment in which expo-updates is disabled, this object is empty.

Updates.runtimeVersion

Android
iOS
tvOS

Type: string | null

The runtime version of the current build.

Updates.updateId

Android
iOS
tvOS

Type: string | null

The UUID that uniquely identifies the currently running update. The UUID is represented in its canonical string form and will always use lowercase letters. This value is null when running in a local development environment or any other environment where expo-updates is disabled.

Example

"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Hooks

useUpdates()

Android
iOS
tvOS

Hook that obtains information on available updates and on the currently running update.

the structures with information on currently running and available updates.

Example

UpdatesDemo.tsx
import { StatusBar } from 'expo-status-bar'; import * as Updates from 'expo-updates'; import { useEffect } from 'react'; import { Button, Text, View } from 'react-native'; export default function UpdatesDemo() { const { currentlyRunning, isUpdateAvailable, isUpdatePending } = Updates.useUpdates(); useEffect(() => { if (isUpdatePending) { // Update has successfully downloaded; apply it now Updates.reloadAsync(); } }, [isUpdatePending]); // If true, we show the button to download and run the update const showDownloadButton = isUpdateAvailable; // Show whether or not we are running embedded code or an update const runTypeMessage = currentlyRunning.isEmbeddedLaunch ? 'This app is running from built-in code' : 'This app is running an update'; return ( <View style={styles.container}> <Text style={styles.headerText}>Updates Demo</Text> <Text>{runTypeMessage}</Text> <Button onPress={() => Updates.checkForUpdateAsync()} title="Check manually for updates" /> {showDownloadButton ? ( <Button onPress={() => Updates.fetchUpdateAsync()} title="Download and run update" /> ) : null} <StatusBar style="auto" /> </View> ); }

Classes

ExpoUpdatesModule

Android
iOS
tvOS

Type: Class extends _default<UpdatesEvents> implements UpdatesModuleInterface

Methods

Updates.checkForUpdateAsync()

Android
iOS
tvOS

Checks the server to see if a newly deployed update to your project is available. Does not actually download the update. This method cannot be used in development mode, and the returned promise will be rejected if you try to do so.

Checking for an update uses a device's bandwidth and battery life like any network call. Additionally, updates served by Expo may be rate limited. A good rule of thumb to check for updates judiciously is to check when the user launches or foregrounds the app. Avoid polling for updates in a frequent loop.

A promise that fulfills with an UpdateCheckResult object.

The promise rejects in Expo Go or if the app is in development mode, or if there is an unexpected error or timeout communicating with the server. It also rejects when expo-updates is not enabled.

Updates.clearLogEntriesAsync()

Android
iOS
tvOS

Clears existing expo-updates log entries.

For now, this operation does nothing on the client. Once log persistence has been implemented, this operation will actually remove existing logs.

Returns:
Promise<void>

A promise that fulfills if the clear operation was successful.

The promise rejects if there is an unexpected error in clearing the logs.

Updates.fetchUpdateAsync()

Android
iOS
tvOS

Downloads the most recently deployed update to your project from server to the device's local storage. This method cannot be used in development mode, and the returned promise will be rejected if you try to do so.

Note: reloadAsync() can be called after promise resolution to reload the app using the most recently downloaded version. Otherwise, the update will be applied on the next app cold start.

A promise that fulfills with an UpdateFetchResult object.

The promise rejects in Expo Go or if the app is in development mode, or if there is an unexpected error or timeout communicating with the server. It also rejects when expo-updates is not enabled.

Updates.getExtraParamsAsync()

Android
iOS
tvOS

Retrieves the current extra params.

This method cannot be used in Expo Go or development mode. It also rejects when expo-updates is not enabled.

Returns:
Promise<Record<string, string>>

Updates.readLogEntriesAsync(maxAge)

Android
iOS
tvOS
ParameterTypeDescription
maxAge(optional)number

Sets the max age of retrieved log entries in milliseconds. Default to 3600000 ms (1 hour).

Default:3600000

Retrieves the most recent expo-updates log entries.

A promise that fulfills with an array of UpdatesLogEntry objects;

The promise rejects if there is an unexpected error in retrieving the logs.

Updates.reloadAsync()

Android
iOS
tvOS

Instructs the app to reload using the most recently downloaded version. This is useful for triggering a newly downloaded update to launch without the user needing to manually restart the app. Unlike Expo.reloadAppAsync() provided by the expo package, this function not only reloads the app but also changes the loaded JavaScript bundle to that of the most recently downloaded update.

It is not recommended to place any meaningful logic after a call to await Updates.reloadAsync(). This is because the promise is resolved after verifying that the app can be reloaded, and immediately before posting an asynchronous task to the main thread to actually reload the app. It is unsafe to make any assumptions about whether any more JS code will be executed after the Updates.reloadAsync method call resolves, since that depends on the OS and the state of the native module and main threads.

This method cannot be used in Expo Go or development mode, and the returned promise will be rejected if you try to do so. It also rejects when expo-updates is not enabled.

Returns:
Promise<void>

A promise that fulfills right before the reload instruction is sent to the JS runtime, or rejects if it cannot find a reference to the JS runtime. If the promise is rejected in production mode, it most likely means you have installed the module incorrectly. Double check you've followed the installation instructions. In particular, on iOS ensure that you set the bridge property on EXUpdatesAppController with a pointer to the RCTBridge you want to reload, and on Android ensure you either call UpdatesController.initialize with the instance of ReactApplication you want to reload, or call UpdatesController.setReactNativeHost with the proper instance of ReactNativeHost.

Updates.setExtraParamAsync(key, value)

Android
iOS
tvOS
ParameterType
keystring
valueundefined | null | string

Sets an extra param if value is non-null, otherwise unsets the param. Extra params are sent as an Expo Structured Field Value Dictionary in the Expo-Extra-Params header of update requests. A compliant update server may use these params when selecting an update to serve.

This method cannot be used in Expo Go or development mode. It also rejects when expo-updates is not enabled.

Returns:
Promise<void>

Updates.setUpdateURLAndRequestHeadersOverride(configOverride)

Experimental
 • 
Android
iOS
tvOS
ParameterType
configOverridenull | { requestHeaders: Record<string, string>, updateUrl: string }

Overrides updates URL and reuqest headers in runtime from build time. This method allows you to load specific updates from a URL that you provide. Use this method at your own risk, as it may cause unexpected behavior. Learn more about use cases and limitations.

Returns:
void

Interfaces

UpdatesModuleInterface

Android
iOS
tvOS

Common interface for all native module implementations (android, ios, web).

PropertyTypeDescription
channelstring

Can be empty string

checkAutomaticallyUpdatesCheckAutomaticallyNativeValue
-
checkForUpdateAsync() => Promise<UpdateCheckResultRollBack | UpdateCheckResultNotAvailable | Omit<UpdateCheckResultAvailable, "manifest"> & ({ manifestString: string; } | { manifest: Manifest; })>
-
clearLogEntriesAsync() => Promise<void>
-
commitTime(optional)string
-
emergencyLaunchReasonnull | string
-
fetchUpdateAsync() => Promise<UpdateFetchResultFailure | UpdateFetchResultRollBackToEmbedded | Omit<UpdateFetchResultSuccess, "manifest"> & ({ manifestString: string; } | { manifest: Manifest; })>
-
getExtraParamsAsync() => Promise<Record<string, string>>
-
initialContextUpdatesNativeStateMachineContext & { downloadedManifestString: string, lastCheckForUpdateTimeString: string, latestManifestString: string, rollbackString: string }
-
isEmbeddedLaunchboolean
-
isEmergencyLaunchboolean
-
isEnabledboolean
-
isUsingEmbeddedAssets(optional)boolean
-
launchDurationnull | number
-
localAssets(optional)Record<string, string>
-
manifest(optional)Manifest
Only for:
iOS

-
manifestString(optional)string
Only for:
Android

-
readLogEntriesAsync(maxAge: number) => Promise<UpdatesLogEntry[]>
-
reload() => Promise<void>
-
runtimeVersionstring

Can be empty string

setExtraParamAsync(key: string, value: null | string) => Promise<void>
-
shouldDeferToNativeForAPIMethodAvailabilityInDevelopmentboolean
-
updateId(optional)string
-

Types

CurrentlyRunningInfo

Android
iOS
tvOS

Structure encapsulating information on the currently running app (either the embedded bundle or a downloaded update).

PropertyTypeDescription
channel(optional)string

The channel name of the current build, if configured for use with EAS Update, undefined otherwise.

createdAt(optional)Date

If expo-updates is enabled, this is a Date object representing the creation time of the update that's currently running (whether it was embedded or downloaded at runtime).

In development mode, or any other environment in which expo-updates is disabled, this value is undefined.

emergencyLaunchReasonstring | null

If isEmergencyLaunch is set to true, this will contain a string error message describing what failed during initialization.

isEmbeddedLaunchboolean

This will be true if the currently running update is the one embedded in the build, and not one downloaded from the updates server.

isEmergencyLaunchboolean

expo-updates does its very best to always launch monotonically newer versions of your app so you don't need to worry about backwards compatibility when you put out an update. In very rare cases, it's possible that expo-updates may need to fall back to the update that's embedded in the app binary, even after newer updates have been downloaded and run (an "emergency launch"). This boolean will be true if the app is launching under this fallback mechanism and false otherwise. If you are concerned about backwards compatibility of future updates to your app, you can use this constant to provide special behavior for this rare case.

launchDuration(optional)number

Number of milliseconds it took to launch.

manifest(optional)Partial<Manifest>

If expo-updates is enabled, this is the manifest object for the update that's currently running.

In development mode, or any other environment in which expo-updates is disabled, this object is empty.

runtimeVersion(optional)string

The runtime version of the current build.

updateId(optional)string

The UUID that uniquely identifies the currently running update if expo-updates is enabled. The UUID is represented in its canonical string form and will always use lowercase letters. In development mode, or any other environment in which expo-updates is disabled, this value is undefined.

Example

"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Manifest

Android
iOS
tvOS

Literal Type: union

Acceptable values are: ExpoUpdatesManifest | EmbeddedManifest

UpdateCheckResult

Android
iOS
tvOS

Literal Type: union

The result of checking for a new update.

Acceptable values are: UpdateCheckResultRollBack | UpdateCheckResultAvailable | UpdateCheckResultNotAvailable

UpdateCheckResultAvailable

Android
iOS
tvOS

The update check result when a new update is found on the server.

PropertyTypeDescription
isAvailabletrue

Whether an update is available. This property is false for a roll back update.

isRollBackToEmbeddedfalse

Whether a roll back to embedded update is available.

manifestManifest

The manifest of the update when available.

reasonundefined

If no new update is found, this contains one of several enum values indicating the reason.

UpdateCheckResultNotAvailable

Android
iOS
tvOS

The update check result if no new update was found.

PropertyTypeDescription
isAvailablefalse

Whether an update is available. This property is false for a roll back update.

isRollBackToEmbeddedfalse

Whether a roll back to embedded update is available.

manifestundefined

The manifest of the update when available.

reasonUpdateCheckResultNotAvailableReason

If no new update is found, this contains one of several enum values indicating the reason.

UpdateCheckResultRollBack

Android
iOS
tvOS

The update check result when a rollback directive is received.

PropertyTypeDescription
isAvailablefalse

Whether an update is available. This property is false for a roll back update.

isRollBackToEmbeddedtrue

Whether a roll back to embedded update is available.

manifestundefined

The manifest of the update when available.

reasonundefined

If no new update is found, this contains one of several enum values indicating the reason.

UpdateFetchResult

Android
iOS
tvOS

Literal Type: union

The result of fetching a new update.

Acceptable values are: UpdateFetchResultSuccess | UpdateFetchResultFailure | UpdateFetchResultRollBackToEmbedded

UpdateFetchResultFailure

Android
iOS
tvOS

The failed result of fetching a new update.

PropertyTypeDescription
isNewfalse

Whether the fetched update is new (that is, a different version than what's currently running). Always false when isRollBackToEmbedded is true.

isRollBackToEmbeddedfalse

Whether the fetched update is a roll back to the embedded update.

manifestundefined

The manifest of the fetched update.

UpdateFetchResultRollBackToEmbedded

Android
iOS
tvOS

The roll back to embedded result of fetching a new update.

PropertyTypeDescription
isNewfalse

Whether the fetched update is new (that is, a different version than what's currently running). Always false when isRollBackToEmbedded is true.

isRollBackToEmbeddedtrue

Whether the fetched update is a roll back to the embedded update.

manifestundefined

The manifest of the fetched update.

UpdateFetchResultSuccess

Android
iOS
tvOS

The successful result of fetching a new update.

PropertyTypeDescription
isNewtrue

Whether the fetched update is new (that is, a different version than what's currently running). Always true when isRollBackToEmbedded is false.

isRollBackToEmbeddedfalse

Whether the fetched update is a roll back to the embedded update.

manifestManifest

The manifest of the fetched update.

UpdateInfo

Android
iOS
tvOS

Literal Type: union

Combined structure representing any type of update.

Acceptable values are: UpdateInfoNew | UpdateInfoRollback

UpdateInfoNew

Android
iOS
tvOS

Structure representing a new update.

PropertyTypeDescription
createdAtDate

For all types of updates, this is a Date object representing the creation time or commit time of the update.

manifestManifest

For updates of type UpdateInfoType.NEW, this is the manifest for the update.

typeUpdateInfoType.NEW

The type of update.

updateIdstring

For updates of type UpdateInfoType.NEW, this is a string that uniquely identifies the update. For the manifests used in the current Expo Updates protocol (including EAS Update), this represents the update's UUID in its canonical string form and will always use lowercase letters.

Example

"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

UpdateInfoRollback

Android
iOS
tvOS

Structure representing a rollback directive.

PropertyTypeDescription
createdAtDate

For all types of updates, this is a Date object representing the creation time or commit time of the update.

manifestundefined

For updates of type UpdateInfoType.ROLLBACK, this is always set to undefined.

typeUpdateInfoType.ROLLBACK

The type of update.

updateIdundefined

For updates of type UpdateInfoType.ROLLBACK, this is always set to undefined.

UpdatesCheckAutomaticallyNativeValue

Android
iOS
tvOS

Literal Type: string

Acceptable values are: 'ALWAYS' | 'ERROR_RECOVERY_ONLY' | 'NEVER' | 'WIFI_ONLY'

UpdatesEvents

Android
iOS
tvOS
PropertyTypeDescription
Expo.nativeUpdatesStateChangeEvent(params: any) => void
-

UpdatesLogEntry

Android
iOS
tvOS

An object representing a single log entry from expo-updates logging on the client.

PropertyTypeDescription
assetId(optional)string

If present, the unique ID or hash of an asset associated with this log entry.

codeUpdatesLogEntryCode

One of the defined code values for expo-updates log entries.

levelUpdatesLogEntryLevel

One of the defined log level or severity values.

messagestring

The log entry message.

stacktrace(optional)string[]

If present, an Android or iOS native stack trace associated with this log entry.

timestampnumber

The time the log was written, in milliseconds since Jan 1 1970 UTC.

updateId(optional)string

If present, the unique ID of an update associated with this log entry.

UseUpdatesReturnType

Android
iOS
tvOS

The type returned by useUpdates().

PropertyTypeDescription
availableUpdate(optional)UpdateInfo

If a new available update has been found, either by using checkForUpdateAsync(), or by the UpdateEvent listener in useUpdates(), this will contain the information for that update.

checkError(optional)Error

If an error is returned from either the startup check for updates, or a call to checkForUpdateAsync(), the error description will appear here.

currentlyRunningCurrentlyRunningInfo

Information on the currently running app.

downloadedUpdate(optional)UpdateInfo

If an available update has been downloaded, this will contain the information for that update.

downloadError(optional)Error

If an error is returned from either a startup update download, or a call to fetchUpdateAsync(), the error description will appear here.

isCheckingboolean

True if the app is currently checking for a new available update from the server.

isDownloadingboolean

True if the app is currently downloading an update from the server.

isRestartingboolean

True if the app is currently in the process of restarting.

isStartupProcedureRunningboolean

Whether the startup procedure is still running. This may happen if the fallbackToCacheTimeout is shorter than the time taken to fetch a new update during app launch.

isUpdateAvailableboolean

True if a new available update has been found, false otherwise.

isUpdatePendingboolean

True if a new available update is available and has been downloaded.

lastCheckForUpdateTimeSinceRestart(optional)Date

A Date object representing the last time this client checked for an available update, or undefined if no check has yet occurred since the app started. Does not persist across app reloads or restarts.

restartCountnumber

Number of times the JS has been restarted (for example, by calling reloadAsync) since app cold start.

Enums

UpdateCheckResultNotAvailableReason

Android
iOS
tvOS

NO_UPDATE_AVAILABLE_ON_SERVER

UpdateCheckResultNotAvailableReason.NO_UPDATE_AVAILABLE_ON_SERVER = "noUpdateAvailableOnServer"

No update manifest or rollback directive received from the update server.

ROLLBACK_NO_EMBEDDED

UpdateCheckResultNotAvailableReason.ROLLBACK_NO_EMBEDDED = "rollbackNoEmbeddedConfiguration"

A rollback directive was received from the update server, but this app has no embedded update.

ROLLBACK_REJECTED_BY_SELECTION_POLICY

UpdateCheckResultNotAvailableReason.ROLLBACK_REJECTED_BY_SELECTION_POLICY = "rollbackRejectedBySelectionPolicy"

A rollback directive was received from the update server, but the directive does not pass the configured selection policy.

UPDATE_PREVIOUSLY_FAILED

UpdateCheckResultNotAvailableReason.UPDATE_PREVIOUSLY_FAILED = "updatePreviouslyFailed"

An update manifest was received from the update server, but the update has been previously launched on this device and never successfully launched.

UPDATE_REJECTED_BY_SELECTION_POLICY

UpdateCheckResultNotAvailableReason.UPDATE_REJECTED_BY_SELECTION_POLICY = "updateRejectedBySelectionPolicy"

An update manifest was received from the update server, but the update is not launchable, or does not pass the configured selection policy.

UpdateInfoType

Android
iOS
tvOS

The different possible types of updates. Currently, the only supported type is UpdateInfoType.NEW, indicating a new update that can be downloaded and launched on the device. In the future, other types of updates may be added to this list.

NEW

UpdateInfoType.NEW = "new"

This is the type for new updates found on or downloaded from the update server, that are launchable on the device.

ROLLBACK

UpdateInfoType.ROLLBACK = "rollback"

This type is used when an update is a directive to roll back to the embedded bundle.

UpdatesCheckAutomaticallyValue

Android
iOS
tvOS

The possible settings that determine if expo-updates will check for updates on app startup. By default, Expo will check for updates every time the app is loaded. Set this to ON_ERROR_RECOVERY to disable automatic checking unless recovering from an error. Set this to NEVER to completely disable automatic checking.

NEVER

UpdatesCheckAutomaticallyValue.NEVER = "NEVER"

Automatic update checks are off, and update checks must be done through the JS API.

ON_ERROR_RECOVERY

UpdatesCheckAutomaticallyValue.ON_ERROR_RECOVERY = "ON_ERROR_RECOVERY"

Only checks for updates when the app starts up after an error recovery.

ON_LOAD

UpdatesCheckAutomaticallyValue.ON_LOAD = "ON_LOAD"

Checks for updates whenever the app is loaded. This is the default setting.

WIFI_ONLY

UpdatesCheckAutomaticallyValue.WIFI_ONLY = "WIFI_ONLY"

Only checks for updates when the app starts and has a Wi-Fi connection.

UpdatesLogEntryCode

Android
iOS
tvOS

The possible code values for expo-updates log entries

ASSETS_FAILED_TO_LOAD

UpdatesLogEntryCode.ASSETS_FAILED_TO_LOAD = "AssetsFailedToLoad"

INITIALIZATION_ERROR

UpdatesLogEntryCode.INITIALIZATION_ERROR = "InitializationError"

JS_RUNTIME_ERROR

UpdatesLogEntryCode.JS_RUNTIME_ERROR = "JSRuntimeError"

NONE

UpdatesLogEntryCode.NONE = "None"

NO_UPDATES_AVAILABLE

UpdatesLogEntryCode.NO_UPDATES_AVAILABLE = "NoUpdatesAvailable"

UNKNOWN

UpdatesLogEntryCode.UNKNOWN = "Unknown"

UPDATE_ASSETS_NOT_AVAILABLE

UpdatesLogEntryCode.UPDATE_ASSETS_NOT_AVAILABLE = "UpdateAssetsNotAvailable"

UPDATE_CODE_SIGNING_ERROR

UpdatesLogEntryCode.UPDATE_CODE_SIGNING_ERROR = "UpdateCodeSigningError"

UPDATE_FAILED_TO_LOAD

UpdatesLogEntryCode.UPDATE_FAILED_TO_LOAD = "UpdateFailedToLoad"

UPDATE_HAS_INVALID_SIGNATURE

UpdatesLogEntryCode.UPDATE_HAS_INVALID_SIGNATURE = "UpdateHasInvalidSignature"

UPDATE_SERVER_UNREACHABLE

UpdatesLogEntryCode.UPDATE_SERVER_UNREACHABLE = "UpdateServerUnreachable"

UpdatesLogEntryLevel

Android
iOS
tvOS

The possible log levels for expo-updates log entries

DEBUG

UpdatesLogEntryLevel.DEBUG = "debug"

ERROR

UpdatesLogEntryLevel.ERROR = "error"

FATAL

UpdatesLogEntryLevel.FATAL = "fatal"

INFO

UpdatesLogEntryLevel.INFO = "info"

TRACE

UpdatesLogEntryLevel.TRACE = "trace"

WARN

UpdatesLogEntryLevel.WARN = "warn"

错误代码

代码描述
ERR_UPDATES_DISABLED在 Updates 库被禁用时,或应用程序正以开发模式运行时,尝试调用某个方法
ERR_UPDATES_RELOAD尝试重新加载应用程序时发生错误,并且无法重新加载。对于裸 React Native 应用,请再次检查此库的设置步骤,以确保已正确安装并调用了正确的原生初始化方法。
ERR_UPDATES_CHECK尝试检查新更新时发生了意外错误。请查看错误信息以获取更多信息。
ERR_UPDATES_FETCH尝试获取新更新时发生了意外错误。请查看错误信息以获取更多信息。
ERR_UPDATES_READ_LOGS尝试读取日志条目时发生了意外错误。请查看错误信息以获取更多信息。
ERR_NOT_AVAILABLE_IN_DEV_CLIENT在开发构建中运行时,某个方法不可用。应使用发布构建来测试此方法。