跳过内容

版本目标

本指南解释了如何自动将最新兼容的包传递给用户,基于他们的本机应用程序版本, 与 Ionic AppFlow 的方法类似。 这确保了简化的更新管理和更快的发布,同时防止兼容性问题。

Capgo的版本目标系统允许您:

  • 自动向用户提供兼容的更新 基于他们的原生应用程序版本
  • 防止破坏性更改 到不兼容的应用程序版本
  • 同时管理多个应用程序版本 无需复杂的逻辑
  • 无缝地向特定用户段落发布更新 向用户基于他们的原生应用程序版本自动提供兼容更新

Why Version Targeting Matters (Especially for AppFlow Users)

关于版本目标的重要性(尤其是AppFlow用户)

If you’re familiar with Ionic AppFlow, you know how critical it is to ensure users receive only compatible updates. AppFlow automatically matched live update bundles to native app versions, preventing incompatible JavaScript from being delivered to older native code.

Capgo 提供相同的安全保证, with additional features:

  • 更细致的版本匹配控制
  • 多种策略(通道、语义版本、原生约束)
  • 更好的版本分布可视化
  • API 和 CLI 控制与仪表盘管理

This approach is particularly useful when:

  • 您有不同大版本的用户(例如,v1.x,v2.x,v3.x)
  • 您需要在推出破坏性更改的同时保持向后兼容性
  • 您希望防止新版本的捆绑包破坏旧版本的 code
  • 您正在逐渐从一个版本迁移到另一个版本
  • 您正在从 AppFlow 迁移 并且希望保持相同的更新安全性

Capgo 使用多层次的方法来匹配用户与兼容的更新:

  1. 原生版本约束: 防止捆绑包被分发到不兼容的原生版本
  2. 频道路由: 分别将不同应用版本路由到不同的更新频道
  3. 语义版本控制: 在主要/次要/修订版本边界处自动阻止更新
  4. 设备级别覆盖: targeting特定设备或用户组

版本匹配流程

标题:版本匹配流程
graph TD
A[User Opens App] --> B{Check Device Override}
B -->|Override Set| C[Use Override Channel]
B -->|No Override| D{Check defaultChannel in App}
D -->|Has defaultChannel| E[Use App's defaultChannel]
D -->|No defaultChannel| F[Use Cloud Default Channel]
C --> G{Check Version Constraints}
E --> G
F --> G
G -->|Compatible| H[Deliver Update]
G -->|Incompatible| I[Skip Update]

策略1:基于频道的版本路由

标题:基于频道的版本路由

这是 推荐方法 __CAPGO_KEEP_0__用于管理重大变更和主要版本更新。它与AppFlow的交付模型类似。

__CAPGO_KEEP_0__示例场景

__CAPGO_KEEP_0__标题:示例场景
  • App v1.x (100,000名用户) → production __CAPGO_KEEP_0__
  • App v2.x (50,000名用户带重大变更) → v2 __CAPGO_KEEP_0__
  • App v3.x (10,000名beta用户) → v3 __CAPGO_KEEP_0__

实现

实现

步骤 1:为每个主要版本配置通道

步骤 1:为每个主要版本配置通道
// capacitor.config.ts for version 1.x builds
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'Example App',
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
defaultChannel: 'production', // or omit for default
}
}
};
export default config;
// capacitor.config.ts for version 2.x builds
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'Example App',
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
defaultChannel: 'v2', // Routes v2 users automatically
}
}
};
// capacitor.config.ts for version 3.x builds
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'Example App',
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
defaultChannel: 'v3', // Routes v3 users automatically
}
}
};

步骤 2:创建通道

终端窗口
复制到剪贴板
# Create channels for each major version
npx @capgo/cli channel create production
npx @capgo/cli channel create v2
npx @capgo/cli channel create v3
# Enable self-assignment so apps can switch channels
npx @capgo/cli channel set production --self-assign
npx @capgo/cli channel set v2 --self-assign
npx @capgo/cli channel set v3 --self-assign
终端窗口
# For v1.x users (from v1-maintenance branch)
git checkout v1-maintenance
npm run build
npx @capgo/cli bundle upload --channel production
# For v2.x users (from v2-maintenance or main branch)
git checkout main
npm run build
npx @capgo/cli bundle upload --channel v2
# For v3.x users (from beta/v3 branch)
git checkout beta
npm run build
npx @capgo/cli bundle upload --channel v3

优点

优点
  • Zero code changes 清晰的分离
  • 无需进行任何 __CAPGO_KEEP_0__ 更改 - 每个版本都有自己的更新管道
  • 灵活的目标 - 将更新推送到特定版本组
  • 安全的滚动发布 - 不兼容版本的破坏性更改永远不会到达

策略 2:语义版本控制

标题:策略 2:语义版本控制

使用 Capgo 的内置 语义版本控制 以防止版本边界之间的更新。

禁用主版本之间的自动更新

标题:禁用主版本之间的自动更新
终端窗口
# Create a channel that blocks major version updates
npx @capgo/cli channel create stable --disable-auto-update major

这项配置的含义是:

  • 应用程序版本的用户 1.2.3 将收到更新至 1.9.9
  • 用户将 不会 收到版本 2.0.0 自动
  • 防止破坏性更新到达较旧的本机 code

细粒度控制选项

细粒度控制选项
终端窗口
# Block minor version updates (1.2.x won't get 1.3.0)
npx @capgo/cli channel set stable --disable-auto-update minor
# Block patch updates (1.2.3 won't get 1.2.4)
npx @capgo/cli channel set stable --disable-auto-update patch
# Allow all updates
npx @capgo/cli channel set stable --disable-auto-update none

策略 3: 原生版本约束

策略 3: 原生版本约束

为捆绑包指定最低原生版本要求

以防止将应用程序分发到不兼容的设备上。使用 nativeVersion 延迟条件

Section titled “使用 nativeVersion 延迟条件”

当上传一个捆绑包时,您可以指定一个最小的native版本:

终端窗口
# This bundle requires native version 2.0.0 or higher
npx @capgo/cli bundle upload \
--channel production \
--native-version "2.0.0"
  1. 需要新native插件

    终端窗口
    # Bundle needs Camera plugin added in v2.0.0
    npx @capgo/cli bundle upload --native-version "2.0.0"
  2. 突破本机API更新

    终端窗口
    # Bundle uses new Capacitor 6 APIs
    npx @capgo/cli bundle upload --native-version "3.0.0"
  3. 渐进式迁移

    终端窗口
    # Test bundle only on latest native version
    npx @capgo/cli bundle upload \
    --channel beta \
    --native-version "2.5.0"

策略 4:防止自动降级

标题:策略 4:防止自动降级

防止用户接收比他们当前本机版本更旧的捆绑包。

在 Channel 设置中启用

标题:在 Channel 设置中启用

在Capgo控制台中:

  1. 前往 频道 → 选择您的频道
  2. 启用 “在原生下禁用自动降级”
  3. 保存更改

或通过 CLI:

终端窗口
npx @capgo/cli channel set production --disable-downgrade
  • 用户设备:原生版本 1.2.5
  • 频道捆绑包: 版本 1.2.3
  • 结果: 更新被阻止(将会降级)

以下情况下很有用:

  • 用户手动从应用商店安装了更新的版本
  • 您需要确保用户始终有最新的安全补丁
  • 您想防止回归错误

策略 5:设备级别目标

标题:策略 5:设备级别目标

为特定设备或用户组覆盖频道分配

强制特定版本进行测试

标题:强制特定版本进行测试
import { CapacitorUpdater } from '@capgo/capacitor-updater'
// Force beta testers to use v3 channel
async function assignBetaTesters() {
const deviceId = await CapacitorUpdater.getDeviceId()
// Check if user is beta tester
if (isBetaTester(userId)) {
await CapacitorUpdater.setChannel({ channel: 'v3' })
}
}

在 Capgo 面板中:

  1. 前往 设备 → 查找设备
  2. 点击 设置频道设置版本
  3. 使用特定频道或打包版本覆盖
  4. 设备将从覆盖的源接收更新

完成AppFlow-风格工作流

标题:完成AppFlow-风格工作流

这是一个完整的例子,结合了所有策略:

1. 初始设置(App v1.0.0)

标题:1. 初始设置(App v1.0.0)
终端窗口
# Create production channel with semver controls
npx @capgo/cli channel create production \
--disable-auto-update major \
--disable-downgrade
capacitor.config.ts
const config: CapacitorConfig = {
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
defaultChannel: 'production',
}
}
};

2. App v2.0.0 中的重大更改

标题:2. App v2.0.0 中的重大更改
终端窗口
# Create v2 channel for new version
npx @capgo/cli channel create v2 \
--disable-auto-update major \
--disable-downgrade \
--self-assign
# Create git branch for v1 maintenance
git checkout -b v1-maintenance
git push origin v1-maintenance
// capacitor.config.ts for v2.0.0
const config: CapacitorConfig = {
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
defaultChannel: 'v2', // New users get v2 channel
}
}
};

3. 同时推送更新

标题:3. 同时推送更新
终端窗口
# Update v1.x users (bug fix)
git checkout v1-maintenance
# Make changes
npx @capgo/cli bundle upload \
--channel production \
--native-version "1.0.0"
# Update v2.x users (new feature)
git checkout main
# Make changes
npx @capgo/cli bundle upload \
--channel v2 \
--native-version "2.0.0"

4. 监控版本分布

标题:4. 监控版本分布

使用Capgo控制台来跟踪:

  • v1 和 v2 中的用户数量
  • 每个版本的捆绑采用率
  • 每个版本的错误或崩溃

5. 废弃旧版本

标题:5. 废弃旧版本

当 v1 使用量低于阈值时:

终端窗口
# Stop uploading to production channel
# Optional: Delete v1 maintenance branch
git branch -d v1-maintenance
# Move all remaining users to default
# (They'll need to update via app store)

当存在多个渠道配置时,Capgo使用以下顺序:

  1. 设备Override (控制台或API) - 最高优先级
  2. Cloud Override via setChannel() call
  3. defaultChannel 在 capacitor.config.ts 中
  4. Default Channel (Cloud设置) - 最低优先级

1. 总是为主要版本设置defaultChannel

标题为“1. 总是为主要版本设置defaultChannel”
// ✅ Good: Each major version has explicit channel
// v1.x → production
// v2.x → v2
// v3.x → v3
// ❌ Bad: Relying on dynamic channel switching
// All versions → production, switch manually
终端窗口
# ✅ Good
1.0.0 1.0.1 1.1.0 2.0.0
# ❌ Bad
1.0 1.1 2 2.5
终端窗口
# ✅ Good: Separate branches per major version
main (v3.x)
v2-maintenance (v2.x)
v1-maintenance (v1.x)
# ❌ Bad: Single branch for all versions
终端窗口
# Test on beta channel first
npx @capgo/cli bundle upload --channel beta
# Monitor for issues, then promote to production
npx @capgo/cli bundle upload --channel production

定期检查您的仪表板:

  • 用户是否正在升级到新版本的原生版本?
  • 老版本仍然获得高流量吗?
  • 是否应该弃用旧频道?

与Ionic AppFlow的比较

与Ionic AppFlow的比较

从Ionic AppFlow迁移的团队,请参阅__CAPGO_KEEP_0__的版本目标功能 功能, here’s how Capgo’s version targeting compares:

__CAPGO_KEEP_0__基于版本的路由Capgo
基于原生版本的自动路由基于原生版本的自动路由自动化 defaultChannel + 多种策略
语义版本基本支持高级 --disable-auto-update (主版本/次版本/修订版本)
原生版本约束在 AppFlow 控制台中进行手动配置内置 --native-version 标志在 CLI 中
频道管理Web UI + CLIWeb UI + CLI + API
设备覆盖设备级别控制有限通过控制台/API 完全控制
防止自动降级是通过 --disable-downgrade
多版本维护手动管理分支/频道自动使用频道顺序
自主托管Yes (full control)
版本分析Basic详细每个版本的指标

故障排除

故障排除

用户未接收更新

用户未接收更新

检查以下内容:

  1. 频道分配: 确认设备位于正确频道

    const channel = await CapacitorUpdater.getChannel()
    console.log('Current channel:', channel)
  2. 版本约束: 检查捆绑包是否有原生版本要求

    • 仪表板 → 捆绑包 → 检查“原生版本”列
  3. 语义版本设置: 确认频道的 disable-auto-update 设置

    终端窗口
    npx @capgo/cli channel list
  4. 设备切换: 检查设备是否有手动切换

    • 仪表盘 → 设备 → 搜索设备 → 检查频道/版本
  1. 查看默认频道: 确保频道正确 capacitor.config.ts
  2. 检查包上传: 验证包是否上传到正确的频道
  3. 检查原生版本: 确认 --native-version __CAPGO_KEEP_0__

__CAPGO_KEEP_1__

__CAPGO_KEEP_2__
  1. __CAPGO_KEEP_3____CAPGO_KEEP_4__
    • __CAPGO_KEEP_5__
  2. __CAPGO_KEEP_6____CAPGO_KEEP_7__
  3. __CAPGO_KEEP_8____CAPGO_KEEP_9__

__CAPGO_KEEP_10__

__CAPGO_KEEP_11__

如果您正在从 Ionic AppFlow迁移,版本目标在 Capgo 中与改进的灵活性非常相似:

AppFlow 概念Capgo 等效注意
部署频道Capgo 频道相同概念,更加强大
原生版本锁定--native-version flag更细致的控制
渠道优先级渠道优先级(覆盖 → 云 → 默认)更透明的优先级
部署目标渠道 + semver 控制可用多种策略
生产渠道production 渠道(或任意名称)灵活的命名
基于 Git 的部署CLI 分支上传相同的工作流程
自动匹配版本defaultChannel +版本约束多种策略增强

适用于 AppFlow 用户的关键区别

适用于 AppFlow 用户的区别
  1. 更多控制: Capgo 给您多种策略(通道、semver、原生版本)可组合
  2. 更好的可见性: 版本分布和兼容性问题的仪表盘
  3. API 访问: 全程控制版本目标
  4. : 自主托管: 自行运行更新服务器,同样支持版本逻辑

: 升级步骤

: 升级步骤
  1. : 将 AppFlow 通道映射到 __CAPGO_KEEP_0__ 通道(通常 1:1) to Capgo channels (usually 1:1)
  2. : 在 defaultChannel : 为每个主要版本 capacitor.config.ts : 配置 semver 规则
  3. : 如果您想要在版本边界处自动阻止 : 如果您想要在版本边界处自动阻止
  4. 上传版本特定包 使用 --native-version 标志
  5. 监控版本分布 在Capgo控制台中

逐步版本发布

按版本逐步发布
// Gradually migrate v1 users to v2
async function migrateUsers() {
const deviceId = await CapacitorUpdater.getDeviceId()
const rolloutPercentage = 10 // Start with 10%
// Hash device ID to get deterministic percentage
const hash = hashCode(deviceId) % 100
if (hash < rolloutPercentage) {
// User is in rollout group - migrate to v2
await CapacitorUpdater.setChannel({ channel: 'v2' })
}
}

按版本特性标志

按版本特性标志
// Enable features based on native version
async function checkFeatureAvailability() {
const info = await CapacitorUpdater.getDeviceId()
const nativeVersion = info.nativeVersion
if (compareVersions(nativeVersion, '2.0.0') >= 0) {
// Enable features requiring v2.0.0+
enableNewCameraFeature()
}
}

版本间A/B测试

版本间A/B测试
// Run A/B tests within same native version
async function assignABTest() {
const nativeVersion = await getNativeVersion()
if (nativeVersion.startsWith('2.')) {
// Only A/B test on v2 users
const variant = Math.random() < 0.5 ? 'v2-test-a' : 'v2-test-b'
await CapacitorUpdater.setChannel({ channel: variant })
}
}

Capgo provides multiple strategies for version-specific update delivery:

  1. 按版本逐步发布: 自动版本分离 defaultChannel
  2. Semantic Versioning: 防止更新跨越主/次/修订版本边界
  3. Native Version Constraints: 为捆绑包要求最低的原生版本
  4. Auto-Downgrade Prevention: 永远不向新版原生版本交付旧捆绑包
  5. Device Overrides: 手动控制测试和目标

通过结合这些策略,您可以实现AppFlow样式的自动更新交付,具有更大的灵活性和控制权。 选择最适合您的应用程序版本和部署工作流程的方法。

有关具体功能的更多详细信息:

从版本目标着手

标题:从版本目标着手

如果您正在使用 版本目标 来规划频道路由和阶段性发布,连接它与 频道 来获取频道实现细节 频道 __CAPGO_KEEP_0__ 频道 __CAPGO_KEEP_0__ Beta 测试解决方案 __CAPGO_KEEP_0__ 版本目标解决方案 __CAPGO_KEEP_0__