如何将更新 ID 追溯回 Expo 仪表板

了解如何在使用 EAS Update 和 expo-updates 库时将更新 ID 追溯回 Expo Dashboard。


使用 EAS 更新 时,你可能会遇到需要将 updateId 追溯到 Expo 仪表板 的情况。这可能具有挑战性,因为 Updates.updateId 始终返回一个 ID,无论 Updates.isEmbeddedLaunchtrue 还是 false。但是,如果应用正在运行嵌入式更新,则尝试在 Expo 仪表板 中查找 updateId 将导致错误。发生这种情况是因为仪表板中未跟踪嵌入式更新。

¥When working with EAS Updates, you might encounter a scenario where you need to trace an updateId back to the Expo dashboard. This can be challenging because Updates.updateId always returns an ID, regardless of whether Updates.isEmbeddedLaunch is true or false. However, if the app is running an embedded update, attempting to look up the updateId in the Expo dashboard will result in an error. This happens because embedded updates are not tracked in the dashboard.

确定更新是嵌入还是下载

¥Determine if the update is embedded or downloaded

为了避免此问题,你可以使用 Updates.isEmbeddedLaunch 属性来确定应用是在运行嵌入式更新还是从服务器下载的更新。如果 Updates.isEmbeddedLaunchtrue,则当前正在运行的更新嵌入在构建中,这意味着它将在 Expo 仪表板中不可用。

¥To avoid this issue, you can use the Updates.isEmbeddedLaunch property to determine whether the app is running an embedded update or one downloaded from the server. If Updates.isEmbeddedLaunch is true, the currently running update is embedded in the build, which means it won't be available in the Expo dashboard.

以下是如何显示更新是嵌入还是下载的示例:

¥Here's an example of how you can display whether the update is embedded or downloaded:

UpdateStatus.tsx
import * as Updates from 'expo-updates';
import { Text } from 'react-native';

export default function UpdateStatus() {
  return (
    <Text>
      {Updates.isEmbeddedLaunch
        ? '(Embedded) ❌ You cannot trace this update in the Expo dashboard.'
        : '(Downloaded) ✅ You can trace this update in the Expo dashboard.'}
    </Text>
  );
}

当你导航到 Expo 仪表板中的更新组时(打开你的项目,选择“更新”,然后单击特定更新),URL 显示为:

¥When you navigate to an update group in the Expo dashboard (open your project, select Updates, and click a specific update), the URL displays as:

https://expo.dev/accounts/[accountName]/projects/[projectName]/updates/[updateGroupId]

你可以将 updateGroupId 替换为 Updates.updateId,以直接导航到特定平台更新:

¥You can replace updateGroupId with the Updates.updateId to navigate directly to a specific platform update:

https://expo.dev/accounts/[accountName]/projects/[projectName]/updates/[updateId]

这将打开平台特定更新的相应更新组。

¥This opens the corresponding update group for the platform-specific update.