版本目标
__CAPGO_KEEP_0__
本指南解释了如何自动将最新兼容的捆绑包推送给用户,基于他们的本机应用程序版本 类似于Ionic AppFlow的方法. 这样可以简化更新管理并实现更快的发布,同时防止兼容性问题
__CAPGO_KEEP_0__的版本目标系统允许您:
自动推送兼容更新Capgo’s version targeting system allows you to:
- 概述部分 根据用户的原生应用版本为用户提供内容
- 防止破坏性更改 防止不兼容的应用版本接收更新
- 管理多个应用版本 同时无需复杂逻辑
- 无缝推送更新 到特定用户群
为什么版本目标定位很重要(尤其是AppFlow用户)
标题:为什么版本目标定位很重要(尤其是AppFlow用户)如果您熟悉 Ionic AppFlow,您就知道确保用户只接收兼容更新是多么重要。 AppFlow自动将实时更新包匹配到原生应用版本,防止向较旧的原生code传递不兼容的JavaScript
Capgo 提供相同的安全保证, 还有额外的功能:
- 版本匹配的更细致的控制
- 多种策略(渠道、语义版本号、原生约束)
- 更好的版本分布可视化
- API 和 CLI 与控制台管理一起控制
这种方法特别适用于以下情况:
- 您有不同主版本的用户(例如 v1.x、v2.x、v3.x)
- 您需要维护向后兼容性,同时推出破坏性更改
- 您想防止新版本的捆绑包破坏旧的原生 code
- 您正在逐渐从一个版本迁移到另一个版本
- 您正在从 AppFlow 迁移 并且希望保持相同的更新安全性
如何工作
如何工作Capgo uses a multi-layered approach to match users with compatible updates:
- __CAPGO_KEEP_0__ 使用多层级的方法来匹配用户与兼容的更新:原生版本约束
- :防止不兼容的原生版本分发包通道路由
- :将不同应用版本路由到不同的更新通道语义版本控制
- :自动阻止跨主版本/次版本/修订版本的更新设备级别覆盖项
版本匹配流程
版本匹配流程graph TD A[User Opens App] --> B{Check Device Override} B -->|Override Set| C[Use Override Channel] B -->|No Override| D{Check local plugin channel} D -->|setChannel value| E[Use local setChannel channel] D -->|No local channel| F{Check defaultChannel in App} F -->|Has defaultChannel| G[Use App's defaultChannel] F -->|No defaultChannel| H[Use Cloud Default Channel] C --> I{Check Version Constraints} E --> I G --> I H --> I I -->|Compatible| J[Deliver Update] I -->|Incompatible| K[Skip Update]策略 1:基于渠道的版本路由
基于渠道的版本路由这是一个推荐的方法 用于管理重大变更和主要版本更新。它与 AppFlow 的交付模型类似。 示例场景
示例场景
App v1.x- (100,000 名用户) → 基于渠道的版本路由是管理重大变更和主要版本更新的推荐方法。它类似于 AppFlow 的交付模型。
production频道 - App v2.x (50,000 名用户带有破坏性更改) →
v2频道 - App v3.x (10,000 名 beta 用户) →
v3频道
实现
实现步骤 1:为每个主要版本配置频道
步骤 1:为每个主要版本配置频道// capacitor.config.ts for version 1.x buildsimport { 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 buildsconst 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 buildsconst config: CapacitorConfig = { appId: 'com.example.app', appName: 'Example App', plugins: { CapacitorUpdater: { autoUpdate: 'atBackground', defaultChannel: 'v3', // Routes v3 users automatically } }};步骤 2:创建频道
步骤 2:创建频道# Create channels for each major versionnpx @capgo/cli channel create productionnpx @capgo/cli channel create v2npx @capgo/cli channel create v3
# Enable self-assignment so apps can switch channelsnpx @capgo/cli channel set production --self-assignnpx @capgo/cli channel set v2 --self-assignnpx @capgo/cli channel set v3 --self-assign步骤 3:上传版本特定包
步骤 3:上传版本特定包# For v1.x users (from v1-maintenance branch)git checkout v1-maintenancenpm run buildnpx @capgo/cli bundle upload --channel production
# For v2.x users (from v2-maintenance or main branch)git checkout mainnpm run buildnpx @capgo/cli bundle upload --channel v2
# For v3.x users (from beta/v3 branch)git checkout betanpm run buildnpx @capgo/cli bundle upload --channel v3Benefits
Section titled “Benefits”- Zero code changes - Channel routing happens automatically
- - Each version has its own update pipeline - Flexible targeting
- - Push updates to specific version groups - Safe rollouts
- - Breaking changes never reach incompatible versions Benefits
策略 2:语义版本控制
标题:策略 2:语义版本控制使用 Capgo 内置的 语义版本控制 来防止跨版本更新。
禁用重大版本之间的自动更新
终端窗口# Create a channel that blocks major version updatesnpx @capgo/cli channel create stable --disable-auto-update major应用程序版本的用户
- 将接收更新直到 1.2.3 版本 1.9.9
- 用户将不会 不会 不会自动接收版本 2.0.0 防止破坏性更改到达较旧的本机__CAPGO_KEEP_0__
- Prevents breaking changes from reaching older native code
- 细粒度控制选项
version_build
标题:细粒度控制选项
终端窗口# Block target bundles outside the native major.minor line (1.2.x won't get 1.3.0)npx @capgo/cli channel set stable --disable-auto-update minor
# Block target bundles outside the exact native MAJOR.MINOR.PATCH core (1.2.3 won't get 1.2.4)npx @capgo/cli channel set stable --disable-auto-update patch
# Allow all updatesnpx @capgo/cli channel set stable --disable-auto-update none策略 3:本机版本约束
标题为“策略 3:本机版本约束”在每个捆绑包中指定一个最小的本机应用程序版本(min_update_version)以便Capgo仅将其分发给设备,其本机二进制文件足够新。
本策略使用 渠道 元数据--disable-auto-update metadata策略( --min-update-version 或 --auto-min-update-version __CAPGO_KEEP_0__ --native-version CLI flag.
启用渠道的元数据目标
终端窗口# one-time: require min_update_version metadata on uploads to this channelnpx @capgo/cli@latest channel set production --disable-auto-update metadata设置最低原生版本
当上传一个捆绑包时,请传递可能接收它的最低原生版本:终端窗口
# This bundle requires native version 2.0.0 or highernpx @capgo/cli@latest bundle upload \ --channel production \ --min-update-version "2.0.0"或者让Capgo根据原生包兼容性设置最低版本:
npx @capgo/cli@latest bundle upload \ --channel production \ --auto-min-update-version-
New Native Plugin Required
终端窗口 # Bundle needs Camera plugin added in v2.0.0npx @capgo/cli@latest bundle upload \--channel production \--min-update-version "2.0.0" -
Breaking Native API Changes
终端窗口 # Bundle uses new Capacitor 6 APIsnpx @capgo/cli@latest bundle upload \--channel production \--min-update-version "3.0.0" -
渐进式迁移
终端窗口 # one-time: enable metadata gating on betanpx @capgo/cli@latest channel set beta --disable-auto-update metadata# Test bundle only on latest native versionnpx @capgo/cli@latest bundle upload \--channel beta \--min-update-version "2.5.0"
Strategy 4: Auto-Downgrade Prevention
Section titled “Strategy 4: Auto-Downgrade Prevention”防止用户接收到比他们当前本机版本更旧的捆绑包。
在频道设置中启用。
频道设置启用在Capgo控制台中:
- 前往 频道 选择您的频道
- 启用 “在本机下禁用自动降级”
- 保存更改
或通过CLI:
npx @capgo/cli@latest channel set production --no-downgrade示例
标题:示例- 用户设备:原生版本 1.2.5
- 频道包:版本 1.2.3
- 结果: 更新被阻止(将会是降级)
这在以下情况下很有用:
- 用户手动从应用商店安装了更新的版本
- 您需要确保用户始终有最新的安全补丁
- 您想防止回归错误
策略 5:设备级别目标
Section titled “设备级别目标策略5””为特定设备或用户组覆盖渠道分配。
强制测试特定版本
Section titled “强制测试特定版本””import { CapacitorUpdater } from '@capgo/capacitor-updater'
// Force beta testers to use v3 channelasync function assignBetaTesters() { const deviceId = await CapacitorUpdater.getDeviceId()
// Check if user is beta tester if (isBetaTester(userId)) { await CapacitorUpdater.setChannel({ channel: 'v3' }) }}仪表盘设备覆盖
Section titled “仪表盘设备覆盖””在Capgo仪表盘中:
- 前往 设备 → 查找设备
- 点击 设置频道 或 选择频道或版本
- 或使用特定的频道或版本
- 设备将从覆盖的源接收更新
完整的AppFlow风格工作流
完整的AppFlow风格工作流以下是一个完整的例子,结合了所有策略:
1.初始设置(App v1.0.0)
Section titled “1. Initial Setup (App v1.0.0)”# Create production channel, then enable metadata min-version gatingnpx @capgo/cli@latest channel add productionnpx @capgo/cli@latest channel set production \ --disable-auto-update metadata \ --no-downgradeconst config: CapacitorConfig = { plugins: { CapacitorUpdater: { autoUpdate: 'atBackground', defaultChannel: 'production', } }};Section titled “2. Release Breaking Change (App v2.0.0)”
Section titled “2. Release Breaking Change (App v2.0.0)”# Create v2 channel for new versionnpx @capgo/cli@latest channel add v2npx @capgo/cli@latest channel set v2 \ --disable-auto-update metadata \ --no-downgrade \ --self-assign
# Create git branch for v1 maintenancegit checkout -b v1-maintenancegit push origin v1-maintenance// capacitor.config.ts for v2.0.0const config: CapacitorConfig = { plugins: { CapacitorUpdater: { autoUpdate: 'atBackground', defaultChannel: 'v2', // New users get v2 channel } }};3. 同时推送更新至两版本
终端窗口# Update v1.x users (bug fix)git checkout v1-maintenance# Make changesnpx @capgo/cli@latest bundle upload \ --channel production \ --min-update-version "1.0.0"
# Update v2.x users (new feature)git checkout main# Make changesnpx @capgo/cli@latest bundle upload \ --channel v2 \ --min-update-version "2.0.0"4. 监控版本分布
标题:4. 监控版本分布使用 Capgo 面板来跟踪:
- v1 和 v2 用户数量
- 每个版本的包装采用率
- 每个版本的错误或崩溃率
5. 废弃旧版本
标题:5. 废弃旧版本一旦 v1 使用率低于阈值:
# Stop uploading to production channel# Optional: Delete v1 maintenance branchgit branch -d v1-maintenance
# Move all remaining users to default# (They'll need to update via app store)渠道顺序
渠道顺序当存在多个渠道配置时,Capgo遵循以下顺序:
- 设备覆盖 (控制台或API) - 优先级最高,且在设备覆盖 UI 中可见
- 本地插件渠道 通过
setChannel()- 只存储在设备上,不在设备覆盖 UI 中显示 - defaultChannel 在capacitor.config.ts中
- 默认渠道 (Cloudflare设置) - 优先级最低
标题为“最佳实践”
1. 总是为主要版本设置defaultChannel1. 总是为主要版本设置defaultChannel
Section titled “1. Always Set defaultChannel for Major Versions”// ✅ 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 manually2. 使用语义版本
Section titled “2. 使用语义版本”# ✅ Good1.0.0 → 1.0.1 → 1.1.0 → 2.0.0
# ❌ Bad1.0 → 1.1 → 2 → 2.53. 保持单独的分支
Section titled “3. 保持单独的分支”# ✅ Good: Separate branches per major versionmain (v3.x)v2-maintenance (v2.x)v1-maintenance (v1.x)
# ❌ Bad: Single branch for all versions4. 在发布前进行测试
Section titled “4. 在发布前进行测试”# one-time: create beta and enable metadata gating# (production is set up in the complete workflow above)npx @capgo/cli@latest channel add betanpx @capgo/cli@latest channel set beta --disable-auto-update metadata
# Test on beta channel firstnpx @capgo/cli@latest bundle upload \ --channel beta \ --auto-min-update-version
# Monitor for issues, then promote to productionnpx @capgo/cli@latest bundle upload \ --channel production \ --auto-min-update-version5. 监控版本分布
标题:5. 监控版本分布定期检查您的仪表板:
- 用户是否正在升级到新版本的原生版本?
- 是否仍有旧版本获得高流量?
- 是否应该弃用旧频道?
与Ionic AppFlow的比较
标题:与Ionic AppFlow的比较从Ionic AppFlow迁移的团队 Ionic AppFlow,Capgo的版本目标定位与此处有所不同:
| 功能 | Ionic AppFlow | Capgo |
|---|---|---|
| 版本路由 | 基于原生版本的自动 | 基于 defaultChannel + 多种策略 |
| 语义版本 | 基本支持 | 带有 --disable-auto-update (主版本/次版本/修订版本) |
| 原生版本约束 | 在 AppFlow 控制台中进行手动配置 | 内置 --min-update-version / --auto-min-update-version 带有元数据频道 |
| 频道管理 | Web UI + CLI | Web UI + CLI + API |
| 设备覆盖 | 受限的设备级控制 | 通过 Dashboard/API 进行全控制 |
| 防止自动降级 | 是 | 是通过 --no-downgrade |
| 多版本维护 | 手动分支/频道管理 | 自动(频道优先) |
| 自主托管 | 否 | 是(完全控制) |
| 版本分析 | 基本 | 详细每个版本指标 |
故障排除
故障排除用户未接收更新
故障排除检查以下内容:
-
频道分配: 确认设备位于正确频道
const channel = await CapacitorUpdater.getChannel()console.log('Current channel:', channel) -
版本约束: 检查包是否有本机版本要求
- 仪表盘 → 包 → 检查“本机版本”列
-
Semver 设置: 验证渠道的
disable-auto-update设置终端窗口 npx @capgo/cli channel list -
设备覆盖: 检查设备是否有手动覆盖
- 仪表盘 → 设备 → 搜索设备 → 检查渠道/版本
包送到了错误的版本
标题为“包送到了错误的版本”的部分- Review defaultChannel: 确保正确的频道在
capacitor.config.ts - Check Bundle Upload: 验证包是否已上传到预期的频道
- Inspect min update version: 确认
--min-update-version(或--auto-min-update-version)已设置并且频道使用--disable-auto-update metadata
Breaking Changes Affecting Old Versions
标题:影响旧版本的重大更改- Immediate Fix: 强制受影响设备使用安全包
- 仪表板 → 设备 → 批量选择 → 设置版本
- 长期修复: 创建带有版本号的频道并维护独立分支
- 预防: 在发布之前始终在代表性设备上测试更新
从Ionic AppFlow迁移
标题:从Ionic AppFlow迁移如果您正在从Ionic AppFlow迁移,版本目标功能在__CAPGO_KEEP_0__中与Ionic AppFlow非常相似,但具有更好的灵活性: 概念映射, version targeting works very similarly in Capgo, with improved flexibility:
Long-term Fix
Prevention| AppFlow Concept | Capgo Equivalent | Notes |
|---|---|---|
| 发布渠道 | Capgo 渠道 | 相同概念,更加强大 |
| 原生版本锁定 | --min-update-version / --auto-min-update-version | 更细致的控制 |
| 渠道优先级 | 渠道优先级(覆盖 → 云 → 默认) | 更透明的优先级 |
| 部署目标 | 频道 + semver 控制 | 可用多种策略 |
| 生产频道 | production 频道 (或任意名称) | 灵活的命名 |
| 基于 Git 的部署 | CLI 从分支上传包 | 相同的工作流 |
| 自动匹配版本 | defaultChannel + 版本约束 | 多种策略增强 |
AppFlow 用户的关键区别
Section titled “AppFlow 用户的关键区别”- 更多控制: Capgo 给您多种策略(渠道,semver,原生版本)可组合
- 更好的可见性: 控制台显示版本分布和兼容性问题
- API Access: 对版本目标有完全的程序控制
- 自主托管: 可以使用相同的版本逻辑运行自己的更新服务器
- 映射您的 AppFlow 渠道 到 Capgo 频道(通常为 1:1)
- 设置
defaultChannel在capacitor.config.ts每个主要版本 - 配置 semver 规则 如果您希望在版本边界处自动阻止
- 上传版本特定包 使用
--min-update-version(频道必须使用元数据策略) - 监控版本分布 在 Capgo 控制台
高级模式
标题为“高级模式”按版本逐步发布
标题为“按版本逐步发布”// Gradually migrate v1 users to v2async 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 versionasync 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测试
Section titled “多版本A/B测试”// Run A/B tests within same native versionasync 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 提供多种版本特定更新分发策略:
- 渠道路由: 通过语义版本自动分离版本
defaultChannel - : 防止更新跨越主/次/修订版本原生版本约束
- : 为捆绑包要求最低原生版本防止自动降级
- Channel-Based Routing: 不再向新版原生版本发送旧包
- 设备覆盖: 用于测试和目标的手动控制
通过结合这些策略,您可以实现AppFlow样式的自动更新分发,具有更大的灵活性和控制。 选择最适合您的应用版本和部署工作流程的方法。
有关特定功能的更多详细信息:
- Breaking Changes 指南 详细的渠道版本策略
- 渠道管理 完整的渠道配置参考
- 更新行为 原生版本延迟和条件
继续从版本目标
Section titled “从版本目标定位继续”如果您正在使用 版本目标定位 与其连接 渠道 在渠道中 在渠道中 在渠道中 Beta测试解决方案 在Beta测试解决方案中 for the product workflow in Beta Testing Solution, and for the product workflow in Beta Testing Solution, and 版本目标解决方案 为版本目标解决方案中的产品工作流提供解决方案。