首页指南参考教程

Expo 更新 iconExpo 更新

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

Android
iOS
tvOS

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

¥expo-updates is a library that enables your app to manage remote updates to your application code. It communicates with the configured remote update service to get information about available updates.

安装和配置

¥Installation and configuration

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

¥The expo-updates library can be automatically configured using EAS Update, which is a hosted service that manages and serves updates to your app. To get started with EAS Update, follow the instructions in the Get started guide.

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

¥Alternatively, it is also possible to configure the expo-updates library manually in cases where a different remote update service is required or configuration is only specified in native files.

Manual installation, configuration, and custom remote update services
Terminal
npx expo install expo-updates

如果你要在 裸 React Native 应用 或具有手动配置的原生代码的通用应用中安装此库,请按照这些 安装说明 进行操作。

¥If you're installing this library in a bare React Native app or a generic app with manually configured native code, follow these installation instructions.

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

¥If using app config for configuration, this library can be configured by setting at least the following app config properties:

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

¥The remote service must implement the Expo Updates protocol. EAS Update is one such service, but it is also possible to use this library with a custom server.

定制 Expo 更新服务器

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

其他配置选项

¥Additional configuration options

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

¥These are build-time configuration options that control the behavior of the library. For most apps, these configuration values can be set in the app config under the updates property.

如果你的项目不使用持续原生生成,你还可以在应用的原生项目文件中配置库。也可以从原生代码覆盖配置。

¥You can also configure the library in your app's native project files if your project does not use Continuous Native Generation. It is also possible to override the configuration from native code.

Native configuration instructions

在 Android 上,这些选项在 AndroidManifest.xml 文件中设置为 meta-data 标签(如果使用自动设置,则与安装期间添加的标签相邻)。你还可以使用 UpdatesController.overrideConfiguration() 在运行时设置或覆盖它们。

¥On Android, these options are set as meta-data tags in the AndroidManifest.xml file (adjacent to the tags added during installation if auto-setup was used). You can also set or override them at runtime using UpdatesController.overrideConfiguration().

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

¥On iOS, these properties are set as keys in the Expo.plist file. You can also set or override them at runtime by calling AppController.overrideConfiguration.

Importing Swift generated headers for use in Objective-C++

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

¥If your iOS native code or AppDelegate.mm is written in Objective-C++, you will need to add the following imports to reference methods on EXUpdatesAppController. This is only necessary for overriding configuration at runtime.

#import "ExpoModulesCore-Swift.h"
#import "EXUpdatesInterface-Swift.h"
#import "EXUpdates-Swift.h"
应用配置属性默认必需的?iOS plist/字典键Android 元数据名称Android 地图键
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.codeSigningCertificate(没有任何)EXUpdatesCodeSigningCertificateexpo.modules.updates.CODE_SIGNING_CERTIFICATEcodeSigningCertificate
updates.codeSigningMetadata(没有任何)EXUpdatesCodeSigningMetadataexpo.modules.updates.CODE_SIGNING_METADATAcodeSigningMetadata

用法

¥Usage

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

¥By default, expo-updates checks for updates when the app launches. If an update is available, it downloads the update and applies it the next time the app is restarted. You can tune this startup behavior using the checkAutomatically and fallbackToCacheTimeout configuration options above.

该库还提供了各种常量来检查当前更新,以及从应用代码(启动后)自定义更新行为的函数。例如,一种常见的替代使用模式是在应用启动后手动检查更新,而不是在启动时进行默认检查。

¥The library also provides a variety of constants to inspect the current update and functions to customize update behavior from your application code (after startup). For example, one common alternative usage pattern is to manually check for updates after the app has started instead of doing the default check on launch.

Example: Check for updates manually

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

¥You can configure your app to check for updates manually by doing the following steps:

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

    ¥Set the checkAutomatically configuration value to ON_ERROR_RECOVERY or NEVER to disable the library's default launch behavior.

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

    ¥Add the following code to check for available updates, download them, and reload:

    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) {
          // You can also add an alert() to see the error message in case of an error when fetching updates.
          alert(`Error fetching latest Expo update: ${error}`);
        }
      }
    
      return (
        <View>
          <Button title="Fetch update" onPress={onFetchUpdateAsync} />
        </View>
      );
    }
    

测试

¥Testing

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

¥Most of the methods and constants in this library can be used or tested only in release builds. In debug builds, the default behavior is to always load the latest JavaScript from a development server. It is possible to build a debug version of your app with the same updates behavior as a release build. Such an app will not open the latest JavaScript from your development server — it will load published updates just as a release build does. This may be useful for debugging the behavior of your app when it is not connected to a development server.

要在开发版本中测试更新的内容,请运行 eas update,然后浏览到开发版本中的更新。请注意,这仅模拟更新在你的应用中的样子,并且在开发版本中运行时,大多数 更新 API 不可用。

¥To test the content of an update in a development build, run eas update and then browse to the update in your development build. Note that this only simulates what an update will look like in your app, and most of the Updates API is unavailable when running in a development build.

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

¥To test updates in a release build, you can create a .apk or a simulator build, or make a release build locally with npx expo run:android --variant release and npx expo run:ios --configuration Release (you don't need to submit this build to the store to test). The full Updates API is available in a release build.

要在 Expo Go 中测试更新的内容,请运行 eas update,然后在 Expo Go 中浏览到更新。请注意,这仅模拟更新在你的应用中的样子,并且在 Expo Go 中运行时,大多数 更新 API 不可用。另请注意,仅支持使用 Expo Go 兼容库 的更新。

¥To test the content of an update in Expo Go, run eas update and then browse to the update in Expo Go. Note that this only simulates what an update will look like in your app, and most of the Updates API is unavailable when running in Expo Go. Also note that only updates using Expo Go-compatible libraries are supported.

API

import * as Updates from 'expo-updates';

Constants

Updates.channel

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

Type: UpdatesCheckAutomaticallyValue | null


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

Updates.createdAt

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

Type: null | string


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

Updates.isEmbeddedLaunch

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

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

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.manifest

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

Type: string | null


The runtime version of the current build.

Updates.updateId

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()

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

Returns:

UseUpdatesReturnType

the structures with information on currently running and available updates.

Example

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>
  );
}

Methods

Updates.checkForUpdateAsync()

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.

Returns:

Promise<UpdateCheckResult>

Updates.clearLogEntriesAsync()

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()

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.

Returns:

Promise<UpdateFetchResult>

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()

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)

NameTypeDescription
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.

Returns:

Promise<UpdatesLogEntry[]>

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()

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)

NameType
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>

Interfaces

ExpoUpdatesModule

Extends: Pick<ProxyNativeModule, 'addListener' | 'removeListeners'>

ExpoUpdatesModule Properties

NameTypeDescription
channelstring

Can be empty string

checkAutomaticallystring-
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>>-
isEmbeddedLaunchboolean-
isEmergencyLaunchboolean-
isEnabledboolean-
isUsingEmbeddedAssets
(optional)
boolean-
localAssets
(optional)
Record<string, string>-
manifest
(optional)
Manifest-
manifestString
(optional)
string-
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

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

NameTypeDescription
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.

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

Literal Type: multiple types

Acceptable values are: ExpoUpdatesManifest | EmbeddedManifest

UpdateCheckResult

Literal Type: multiple types

The result of checking for a new update.

Acceptable values are: UpdateCheckResultRollBack | UpdateCheckResultAvailable | UpdateCheckResultNotAvailable

UpdateCheckResultAvailable

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

NameTypeDescription
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.

Deprecated

UpdateCheckResultFailure

Type: UpdateCheckResultNotAvailable

UpdateCheckResultNotAvailable

The update check result if no new update was found.

NameTypeDescription
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

The update check result when a rollback directive is received.

NameTypeDescription
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.

Deprecated

UpdateCheckResultSuccess

Type: UpdateCheckResultAvailable

UpdateFetchResult

Literal Type: multiple types

The result of fetching a new update.

Acceptable values are: UpdateFetchResultSuccess | UpdateFetchResultFailure | UpdateFetchResultRollBackToEmbedded

UpdateFetchResultFailure

The failed result of fetching a new update.

NameTypeDescription
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

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

NameTypeDescription
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

The successful result of fetching a new update.

NameTypeDescription
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

Literal Type: multiple types

Combined structure representing any type of update.

Acceptable values are: UpdateInfoNew | UpdateInfoRollback

UpdateInfoNew

Structure representing a new update.

NameTypeDescription
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

Structure representing a rollback directive.

NameTypeDescription
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.

UpdatesLogEntry

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

NameTypeDescription
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

The structures and methods returned by useUpdates().

NameTypeDescription
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.

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.

downloadedUpdate
(optional)
UpdateInfo

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

initializationError
(optional)
Error

If an error occurs during initialization of useUpdates(), 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.

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.

Enums

UpdateCheckResultNotAvailableReason

UpdateCheckResultNotAvailableReason Values

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

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.

UpdateInfoType Values

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

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.

UpdatesCheckAutomaticallyValue Values

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

The possible code values for expo-updates log entries

UpdatesLogEntryCode Values

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

The possible log levels for expo-updates log entries

UpdatesLogEntryLevel Values

DEBUG

UpdatesLogEntryLevel.DEBUG = "debug"

ERROR

UpdatesLogEntryLevel.ERROR = "error"

FATAL

UpdatesLogEntryLevel.FATAL = "fatal"

INFO

UpdatesLogEntryLevel.INFO = "info"

TRACE

UpdatesLogEntryLevel.TRACE = "trace"

WARN

UpdatesLogEntryLevel.WARN = "warn"

错误代码

¥Error codes

代码描述
ERR_UPDATES_DISABLED在禁用更新库或应用在开发模式下运行时尝试方法调用
ERR_UPDATES_RELOAD尝试重新加载应用时发生错误,无法重新加载。对于裸工作流应用,请仔细检查此库的设置步骤,以确保已正确安装并调用了正确的原生初始化方法。
ERR_UPDATES_CHECK尝试检查新更新时发生意外错误。检查错误消息以获取更多信息。
ERR_UPDATES_FETCH尝试获取新更新时发生意外错误。检查错误消息以获取更多信息。
ERR_UPDATES_READ_LOGS尝试读取日志条目时发生意外错误。检查错误消息以获取更多信息。
ERR_NOT_AVAILABLE_IN_DEV_CLIENT在开发构建中运行时方法不可用。应使用发布版本来测试此方法。
Expo 中文网 - 粤ICP备13048890号