Expo 更新
使你的应用能够管理应用代码远程更新的库。
expo-updates 是一个库,允许你的应用管理对应用代码的远程更新。它与配置的远程更新服务进行通信,以获取可用更新的信息。
安装
🌐 Installation
expo-updates 库可以通过 EAS Update 自动配置,EAS Update 是一个托管服务,用于管理和提供应用的更新。要开始使用 EAS Update,请按照 入门 指南中的说明操作。
🌐 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.
手动安装、配置和自定义远程更新服务
- 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:
updates.url:一个实现了 Expo Updates 协议 的远程服务的 URLruntimeVersion:一个 运行时版本
远程服务必须实现 Expo Updates 协议。EAS Update 就是其中之一,但也可以将此库与自定义服务器一起使用。
🌐 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.
使用自定义服务器及该服务器的应用示例实现
配置
🌐 Configuration
有一些构建时配置选项可以控制库的行为。对于大多数应用,这些配置值在 应用配置 中的 updates 属性 下设置。
🌐 There are build-time configuration options that control the behavior of the library. For most apps, these configuration values are set in the app config under the updates property.
| App config property | Default | Required? | iOS plist/dictionary key | Android meta-data name | Android Map key |
|---|---|---|---|---|---|
updates.enabled | true | EXUpdatesEnabled | expo.modules.updates.ENABLED | enabled | |
updates.url | (none) | EXUpdatesURL | expo.modules.updates.EXPO_UPDATE_URL | updateUrl | |
updates.requestHeaders | (none) | EXUpdatesRequestHeaders | expo.modules.updates.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY | requestHeaders | |
runtimeVersion | (none) | EXUpdatesRuntimeVersion | expo.modules.updates.EXPO_RUNTIME_VERSION | runtimeVersion | |
updates.checkAutomatically | ALWAYS | EXUpdatesCheckOnLaunch | expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH | checkOnLaunch | |
updates.fallbackToCacheTimeout | 0 | EXUpdatesLaunchWaitMs | expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS | launchWaitMs | |
updates.useEmbeddedUpdate | true | EXUpdatesHasEmbeddedUpdate | expo.modules.updates.HAS_EMBEDDED_UPDATE | hasEmbeddedUpdate | |
updates.codeSigningCertificate | (none) | EXUpdatesCodeSigningCertificate | expo.modules.updates.CODE_SIGNING_CERTIFICATE | codeSigningCertificate | |
updates.codeSigningMetadata | (none) | EXUpdatesCodeSigningMetadata | expo.modules.updates.CODE_SIGNING_METADATA | codeSigningMetadata | |
updates.assetPatternsToBeBundled | (none) | N/A | N/A | N/A | |
updates.disableAntiBrickingMeasures | false | EXUpdatesDisableAntiBrickingMeasures | expo.modules.updates. DISABLE_ANTI_BRICKING_MEASURES | disableAntiBrickingMeasures |
两个核心必需的配置选项是:
🌐 The two core required configuration options are:
updates.url:库获取远程更新的 URLruntimeVersion:一个 运行时版本
在按照 EAS 更新 入门 指南操作时,这些会自动配置。
🌐 These are configured automatically when following the EAS Update Get started guide.
运行时版本
🌐 Runtime version
每次为应用构建二进制文件时,它都会包含构建时的本地代码和配置,以及本地配置,这种唯一组合由一个称为运行时版本的字符串表示。远程更新会针对一个运行时版本,这意味着只有具有匹配运行时版本的二进制文件才能加载远程更新。
🌐 Each time you build a binary for your app it includes the native code and configuration present at the time of the build as well as native configuration, and this unique combination is represented by a string called a runtime version. A remote update targets one runtime version, indicating that only binaries with a matching runtime version can load the remote update.
手动配置
运行时版本可以通过在配置字段中设置字符串值来手动管理。
🌐 The runtime version can be managed manually by setting the string value in the config field.
{ "expo": { "runtimeVersion": "<runtime_version_string>" } }
Automatic configuration using runtime version policies
运行时版本策略从项目中已存在的其他信息推导运行时版本。它们可以在 runtimeVersion 配置字段中设置,如下所示:
🌐 Runtime version policies derive the runtime version from another piece of information already present in your project. They can be set in the runtimeVersion config field as follows:
{ "expo": { "runtimeVersion": { "policy": "<policy_name>" } } }
可用的保单类型:
🌐 Available policy types:
appVersion
"appVersion" 策略适用于希望根据应用版本定义其运行时兼容性的项目。
🌐 The "appVersion" policy is provided for projects with that wish to define their runtime compatibility based on the app version.
例如,在一个项目的应用配置中包含以下内容时:
🌐 For example, in a project that has the following in its app config:
{ "expo": { "runtimeVersion": { "policy": "appVersion" }, "version": "1.0.0", "ios": { "buildNumber": "1" }, "android": { "versionCode": 1 } } }
"appVersion" 策略将把运行时版本设置为项目当前的 "version" 属性。在这种情况下,Android 和 iOS 构建以及任何更新的运行时版本都将是 "1.0.0"。
🌐 The "appVersion" policy will set the runtime version to the project's current "version" property. In this case, the runtime version for the Android and iOS builds and any updates would be "1.0.0".
此策略非常适用于包含自定义原生代码且在每次公开发布后都会更新 "version" 字段的项目。要提交应用,应用商店要求每次提交的构建都提供更新的原生版本号,因此如果你希望确保安装在用户设备上的每个版本都有不同的运行时版本,这一策略会非常方便。
🌐 This policy is great for projects that contain custom native code and that update the "version" field after every public release. To submit an app, the app stores require an updated native version number for each submitted build, which makes this policy convenient if you want to be sure that every version installed on user devices has a different runtime version.
使用此策略时,每次有公开版本发布时,你需要手动更新应用配置中的 "version" 字段,但对于 Play 商店的内部测试渠道和 App Store 的 TestFlight 上传,你可以依赖 eas.json 中的 "autoIncrement" 选项来为你管理版本。
🌐 When using this policy, you need to manually update "version" field in the app config every time there is a public release, but for Play Store's Internal Test Track and the App Store's TestFlight uploads, you can rely on "autoIncrement" option in eas.json to manage versions for you.
nativeVersion
"nativeVersion" 策略适用于希望根据项目当前的 "version" 和 "versionCode"(Android)或 "buildNumber"(iOS)属性来定义其运行时兼容性的项目。
🌐 The "nativeVersion" policy is provided for projects that wish to define their runtime compatibility based on the project's current "version" and "versionCode" (Android) or "buildNumber" (iOS) properties.
例如,在一个项目的应用配置中包含以下内容时:
🌐 For example, in a project that has the following in its app config:
{ "expo": { "runtimeVersion": { "policy": "nativeVersion" }, "version": "1.0.0", "ios": { "buildNumber": "1" }, "android": { "versionCode": 1 } } }
Android 和 iOS 构建的运行时版本以及任何更新将是 "[version]([buildNumber|versionCode])" 的组合,在本例中为 "1.0.0(1)"。
🌐 The runtime version for the Android and iOS builds and any updates would be the combination of "[version]([buildNumber|versionCode])", which in this case would be "1.0.0(1)".
该政策非常适用于包含自定义原生代码的项目,这些项目会在每次构建时更新原生版本号(iOS 为 "buildNumber",Android 为 "versionCode")。要提交应用,应用商店要求每次提交的构建都必须有更新的原生版本号,因此如果你希望确保上传到 Play 商店内部测试渠道和 App Store 的 TestFlight 分发工具的每个应用都有不同的 runtimeVersion,该政策就非常方便。
🌐 This policy is great for projects containing custom native code that update the native version numbers ("buildNumber" for iOS and "versionCode" for Android) for each build. To submit an app, the app stores require an updated native version number for each submitted build, which makes this policy convenient if you want to be sure that every app uploaded to the Play Store's Internal Test Track and the App Store's TestFlight distribution tools has a different runtimeVersion.
重要的是要知道,这项政策要求在每次构建之间手动管理原生版本号。
🌐 It's important to know that this policy requires management of the native version numbers manually between each build.
另外,如果你在 Android 和 iOS 之间选择了不同的原生版本,你最终将得到具有独立运行时版本的构建和更新。
🌐 Also, if you select a different native version between Android and iOS, you'll end up with builds and updates with separate runtime versions.
fingerprint
"fingerprint" 运行时版本策略会自动为你计算运行时版本,包括在 SDK 升级或添加自定义本地代码等更改时。
🌐 The "fingerprint" runtime version policy automatically calculates the runtime version for you, including through changes like SDK upgrades or adding custom native code.
{ "expo": { "runtimeVersion": { "policy": "fingerprint" } } }
此策略适用于有自定义原生代码和没有自定义原生代码的项目。它通过使用 @expo/fingerprint 包在构建和更新过程中计算项目的哈希值来确定构建更新的兼容性(也称为运行时)。
🌐 This policy works for both projects with and without custom native code. It works by using the @expo/fingerprint package to calculate the hash of your project during builds and updates to determine build-update compatibility (also known as the runtime).
本地配置与覆盖
🌐 Native configuration and overriding
如果你的项目不使用连续本地生成,这些配置值也可以在应用的本地配置文件中设置,或在本地代码初始化期间被覆盖。
🌐 If your project does not use Continuous Native Generation, these configuration values may also be set in your app's native configuration files or overridden during initialization in native code.
本地配置说明
在 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.
导入 Swift 生成的头文件以在 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"
用法
🌐 Usage
默认情况下,expo-updates 会在应用启动时检查更新。如果有可用更新,它会下载更新并在下次重启应用时应用更新。你可以使用上面的 checkAutomatically 和 fallbackToCacheTimeout 配置选项来调整这种启动行为。
🌐 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.
示例:手动检查更新
你可以通过以下步骤配置你的应用以手动检查更新:
🌐 You can configure your app to check for updates manually by doing the following steps:
-
将
checkAutomatically配置值设置为ON_ERROR_RECOVERY或NEVER以禁用库的默认启动行为。 -
添加以下代码以检查可用更新、下载它们并重新加载:
App.jsimport { 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="获取更新" 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,然后在开发版本中浏览该更新。请注意,这仅仅是模拟更新在应用中的样子,大部分 Updates API 在开发版本中不可用。
要在发布版本中测试更新,你可以创建一个 .apk 文件或一个 模拟器版本,或者在本地使用 npx expo run:android --variant release 和 npx expo run:ios --configuration Release 制作发布版本(测试时不需要将此版本提交到商店)。完整的 更新 API 在发布版本中可用。
在 Expo Go 中测试更新内容,运行 eas update,然后在 Expo Go 中浏览该更新。请注意,这仅模拟更新在应用中的显示效果,并且在 Expo Go 中运行时,大部分 Updates API 无法使用。另外请注意,仅支持使用 兼容 Expo Go 的库 的更新。
应用接口
🌐 API
import * as Updates from 'expo-updates';
Constants
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.
Type: UpdatesCheckAutomaticallyValue | null
Determines if and when expo-updates checks for and downloads updates automatically on startup.
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.
Type: null | string
If isEmergencyLaunch is set to true, this will contain a string error message describing
what failed during initialization.
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.
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.
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.
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.
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
Hook that obtains information on available updates and on the currently running update.
UseUpdatesReturnTypethe 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> ); }
Classes
Type: Class extends NativeModule<UpdatesEvents> implements UpdatesModuleInterface
Methods
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.
Promise<UpdateCheckResult>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.
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.
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.
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.
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.
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.
Promise<Record<string, string>>| Parameter | Type | Description |
|---|---|---|
| maxAge(optional) | number | Sets the max age of retrieved log entries in milliseconds. Default to Default: 3600000 |
Retrieves the most recent expo-updates log entries.
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.
| Parameter | Type |
|---|---|
| options(optional) | {
reloadScreenOptions: ReloadScreenOptions
} |
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.
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.
| Parameter | Type |
|---|---|
| key | string |
| value | undefined | 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.
Promise<void>| Parameter | Type |
|---|---|
| requestHeaders | null | Record<string, string> |
Overrides updates request headers in runtime from build time. This method allows you to load specific updates with custom request headers. Use this method at your own risk, as it may cause unexpected behavior. Learn more about use cases and limitations.
void| Parameter | Type |
|---|---|
| configOverride | null | {
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.
Because of the risk, this method requires disableAntiBrickingMeasures to be set to true in the app.json file.
Learn more about use cases and limitations.
voidInterfaces
Image source that can be used for the reload screen.
| Property | Type | Description |
|---|---|---|
| height(optional) | number | Height of the image in pixels. |
| scale(optional) | number | Scale factor of the image. |
| url(optional) | string | URL to the image. |
| width(optional) | number | Width of the image in pixels. |
Configuration options for customizing the reload screen appearance.
| Property | Type | Description |
|---|---|---|
| backgroundColor(optional) | string | Background color for the reload screen. Default: '#ffffff' |
| fade(optional) | boolean | Whether to fade out the reload screen when hiding. Default: false |
| image(optional) | string | number | ReloadScreenImageSource | Custom image to display on the reload screen. |
| imageFullScreen(optional) | boolean | Whether to display the image at the full screen size. Default: false |
| imageResizeMode(optional) | 'contain' | 'cover' | 'center' | 'stretch' | How to resize the custom image to fit the screen. Default: 'contain' |
| spinner(optional) | {
color: string,
enabled: boolean,
size: 'small' | 'medium' | 'large'
} | Configuration for the loading spinner. |
Common interface for all native module implementations (android, ios, web).
| Property | Type | Description |
|---|---|---|
| channel | string | Can be empty string |
| checkAutomatically | UpdatesCheckAutomaticallyNativeValue | - |
| checkForUpdateAsync | () => Promise<UpdateCheckResultRollBack | UpdateCheckResultNotAvailable | Omit<UpdateCheckResultAvailable, "manifest"> & ({ manifestString: string; } | { manifest: Manifest; })> | - |
| clearLogEntriesAsync | () => Promise<void> | - |
| commitTime(optional) | string | - |
| emergencyLaunchReason | null | string | - |
| fetchUpdateAsync | () => Promise<UpdateFetchResultFailure | UpdateFetchResultRollBackToEmbedded | Omit<UpdateFetchResultSuccess, "manifest"> & ({ manifestString: string; } | { manifest: Manifest; })> | - |
| getExtraParamsAsync | () => Promise<Record<string, string>> | - |
| initialContext | UpdatesNativeStateMachineContext & {
downloadedManifestString: string,
lastCheckForUpdateTimeString: string,
latestManifestString: string,
rollbackString: string
} | - |
| isEmbeddedLaunch | boolean | - |
| isEmergencyLaunch | boolean | - |
| isEnabled | boolean | - |
| isUsingEmbeddedAssets(optional) | boolean | - |
| launchDuration | null | 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> | - |
| runtimeVersion | string | Can be empty string |
| setExtraParamAsync | (key: string, value: null | string) => Promise<void> | - |
| shouldDeferToNativeForAPIMethodAvailabilityInDevelopment | boolean | - |
| updateId(optional) | string | - |
Types
Structure encapsulating information on the currently running app (either the embedded bundle or a downloaded update).
| Property | Type | Description |
|---|---|---|
| channel(optional) | string | The channel name of the current build, if configured for use with EAS Update, |
| createdAt(optional) | Date | If In development mode, or any other environment in which |
| emergencyLaunchReason | string | null | If |
| isEmbeddedLaunch | 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. |
| isEmergencyLaunch | boolean |
|
| launchDuration(optional) | number | Number of milliseconds it took to launch. |
| manifest(optional) | Partial<Manifest> | If In development mode, or any other environment in which |
| runtimeVersion(optional) | string | The runtime version of the current build. |
| updateId(optional) | string | The UUID that uniquely identifies the currently running update if Example
|
Literal Type: union
Acceptable values are: ExpoUpdatesManifest | EmbeddedManifest
Literal Type: union
The result of checking for a new update.
Acceptable values are: UpdateCheckResultRollBack | UpdateCheckResultAvailable | UpdateCheckResultNotAvailable
The update check result when a new update is found on the server.
| Property | Type | Description |
|---|---|---|
| isAvailable | true | Whether an update is available. This property is false for a roll back update. |
| isRollBackToEmbedded | false | Whether a roll back to embedded update is available. |
| manifest | Manifest | The manifest of the update when available. |
| reason | undefined | If no new update is found, this contains one of several enum values indicating the reason. |
The update check result if no new update was found.
| Property | Type | Description |
|---|---|---|
| isAvailable | false | Whether an update is available. This property is false for a roll back update. |
| isRollBackToEmbedded | false | Whether a roll back to embedded update is available. |
| manifest | undefined | The manifest of the update when available. |
| reason | UpdateCheckResultNotAvailableReason | If no new update is found, this contains one of several enum values indicating the reason. |
The update check result when a rollback directive is received.
| Property | Type | Description |
|---|---|---|
| isAvailable | false | Whether an update is available. This property is false for a roll back update. |
| isRollBackToEmbedded | true | Whether a roll back to embedded update is available. |
| manifest | undefined | The manifest of the update when available. |
| reason | undefined | If no new update is found, this contains one of several enum values indicating the reason. |
Literal Type: union
The result of fetching a new update.
Acceptable values are: UpdateFetchResultSuccess | UpdateFetchResultFailure | UpdateFetchResultRollBackToEmbedded
The failed result of fetching a new update.
| Property | Type | Description |
|---|---|---|
| isNew | false | Whether the fetched update is new (that is, a different version than what's currently running).
Always |
| isRollBackToEmbedded | false | Whether the fetched update is a roll back to the embedded update. |
| manifest | undefined | The manifest of the fetched update. |
The roll back to embedded result of fetching a new update.
| Property | Type | Description |
|---|---|---|
| isNew | false | Whether the fetched update is new (that is, a different version than what's currently running).
Always |
| isRollBackToEmbedded | true | Whether the fetched update is a roll back to the embedded update. |
| manifest | undefined | The manifest of the fetched update. |
The successful result of fetching a new update.
| Property | Type | Description |
|---|---|---|
| isNew | true | Whether the fetched update is new (that is, a different version than what's currently running).
Always |
| isRollBackToEmbedded | false | Whether the fetched update is a roll back to the embedded update. |
| manifest | Manifest | The manifest of the fetched update. |
Literal Type: union
Combined structure representing any type of update.
Acceptable values are: UpdateInfoNew | UpdateInfoRollback
Structure representing a new update.
| Property | Type | Description |
|---|---|---|
| createdAt | Date | For all types of updates, this is
a |
| manifest | Manifest | For updates of type |
| type | UpdateInfoType.NEW | The type of update. |
| updateId | string | For updates of type Example
|
Structure representing a rollback directive.
| Property | Type | Description |
|---|---|---|
| createdAt | Date | For all types of updates, this is
a |
| manifest | undefined | For updates of type |
| type | UpdateInfoType.ROLLBACK | The type of update. |
| updateId | undefined | For updates of type |
Literal Type: string
Acceptable values are: 'ALWAYS' | 'ERROR_RECOVERY_ONLY' | 'NEVER' | 'WIFI_ONLY'
| Property | Type | Description |
|---|---|---|
| Expo.nativeUpdatesStateChangeEvent | (params: any) => void | - |
An object representing a single log entry from expo-updates logging on the client.
| Property | Type | Description |
|---|---|---|
| assetId(optional) | string | If present, the unique ID or hash of an asset associated with this log entry. |
| code | UpdatesLogEntryCode | One of the defined code values for |
| level | UpdatesLogEntryLevel | One of the defined log level or severity values. |
| message | string | The log entry message. |
| stacktrace(optional) | string[] | If present, an Android or iOS native stack trace associated with this log entry. |
| timestamp | number | 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. |
The type returned by useUpdates().
| Property | Type | Description |
|---|---|---|
| availableUpdate(optional) | UpdateInfo | If a new available update has been found, either by using |
| checkError(optional) | Error | If an error is returned from either the startup check for updates, or a call to |
| currentlyRunning | CurrentlyRunningInfo | 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 |
| downloadProgress(optional) | number | If |
| isChecking | boolean | True if the app is currently checking for a new available update from the server. |
| isDownloading | boolean | True if the app is currently downloading an update from the server. |
| isRestarting | boolean | True if the app is currently in the process of restarting. |
| isStartupProcedureRunning | boolean | 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. |
| isUpdateAvailable | boolean | True if a new available update has been found, false otherwise. |
| isUpdatePending | boolean | True if a new available update is available and has been downloaded. |
| lastCheckForUpdateTimeSinceRestart(optional) | Date | A |
| restartCount | number | Number of times the JS has been restarted (for example, by calling reloadAsync) since app cold start. |
Enums
UpdateCheckResultNotAvailableReason.NO_UPDATE_AVAILABLE_ON_SERVER = "noUpdateAvailableOnServer"No update manifest or rollback directive received from the update server.
UpdateCheckResultNotAvailableReason.ROLLBACK_NO_EMBEDDED = "rollbackNoEmbeddedConfiguration"A rollback directive was received from the update server, but this app has no embedded update.
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.
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.
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.NEW = "new"This is the type for new updates found on or downloaded from the update server, that are launchable on the device.
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.NEVER = "NEVER"Automatic update checks are off, and update checks must be done through the JS API.
UpdatesCheckAutomaticallyValue.ON_ERROR_RECOVERY = "ON_ERROR_RECOVERY"Only checks for updates when the app starts up after an error recovery.
UpdatesCheckAutomaticallyValue.ON_LOAD = "ON_LOAD"Checks for updates whenever the app is loaded. This is the default setting.
The possible code values for expo-updates log entries
UpdatesLogEntryCode.UPDATE_ASSETS_NOT_AVAILABLE = "UpdateAssetsNotAvailable"UpdatesLogEntryCode.UPDATE_HAS_INVALID_SIGNATURE = "UpdateHasInvalidSignature"The possible log levels for expo-updates log entries
错误代码
🌐 Error codes
| Code | Description |
|---|---|
ERR_UPDATES_DISABLED | A method call was attempted when the Updates library was disabled, or the application was running in development mode |
ERR_UPDATES_RELOAD | An error occurred when trying to reload the application and it could not be reloaded. For bare React Native apps, double-check the setup steps for this library to ensure it has been installed correctly and the proper native initialization methods are called. |
ERR_UPDATES_CHECK | An unexpected error occurred when trying to check for new updates. Check the error message for more information. |
ERR_UPDATES_FETCH | An unexpected error occurred when trying to fetch a new update. Check the error message for more information. |
ERR_UPDATES_READ_LOGS | An unexpected error occurred when trying to read log entries. Check the error message for more information. |
ERR_NOT_AVAILABLE_IN_DEV_CLIENT | A method is not available when running in a development build. A release build should be used to test this method. |