序言
当你开始享受Capgo的更新系统时,就会产生一种‘我想要更多’的感觉
我也产生了这种感觉,但由于我是Capgo的制作者,所以我可以进行查看
由于所有内容都是开源的,你也拥有这种权力:)
在 Capacitor 应用分发过程中,下一个我遇到的痛点是让其他团队成员测试更新!
使用 TestFlight,问题很简单,但将人拉入团队并让他们了解如何获取它的时间花费得很长!
每次向 Apple 发送更新时,你都有一个随机的机器人审查过程,可能花费 5 分钟或 5 小时,你永远不知道。
我经常因为这个原因而推迟我的演讲。
而对于 Google 来说,这甚至更糟糕,我的生活中最大的谜团是:发布生产版本只需要不到 2 小时,但发布闭 beta 版本需要 1–2 天。
解决方案
为了解决这个问题,我在 Capgo 中创建了 Channel 系统。
npx @capgo/cli@latest bundle upload -c production 会更新所有用户(如果设置为默认生产频道)
如果你这样做的话 npx @capgo/cli@latest bundle upload -c development 那么版本就会落在一个不同的频道上,这可以在 __CAPGO_KEEP_0__ 中自动化。 GitHub action.
然后你有两种方式让用户从频道中获取更新
超级自动方式
当您不想为频道设置创建自己的后端时,这可以很有用,快速实现。
只需允许其中一个频道自我设置即可。

And then add this in the code of your Ionic app, for best experience, use this after the user clicks on a button like “register for beta”
import { CapacitorUpdater } from '@capgo/capacitor-updater'
const deviceId = await CapacitorUpdater.setChannel({ channel: 'beta' })
手动方式
这可以用于您的内部团队,快速实现。 允许用户从应用程序中复制设备ID并将其手动发送给您,这个code将有助于您获取它:
import { CapacitorUpdater } from '@capgo/capacitor-updater'
const deviceId = await CapacitorUpdater.getDeviceId()
在应用程序中隐藏一个按钮,或者只向已连接的用户显示按钮,例如。 admin 然后前往Web应用程序或原生应用程序__CAPGO_KEEP_0__,以应用程序管理员身份登录,选择您的应用程序,单击设备列表。
Then Go to the Web app or native app Capgo, connect as app admin, select your app, click on the device list.
,请您的同事打开应用程序,等待30秒,然后打开关闭。 development然后请您的同事打开应用程序,等待30秒,然后打开关闭。
他应该获得您的版本。
自动方式
这对您的beta测试者来说可能很有用,但实现起来更长一些。
与手动方式相同,您必须获取设备ID
import { CapacitorUpdater } from '@capgo/capacitor-updater'
const deviceId = await CapacitorUpdater.getDeviceId()
但这次您必须自动将其发送到您的后端,我让您决定如何做。
我只建议您将其存储在数据库中,这将使您的生活更轻松。
然后,您必须将其发送到Capgo后端。以下是两个code示例:
NodeJS
import axios from 'axios'
await axios.post('https://api.capgo.app/device', {
app_id: 'YOUR_APP_ID',
device_id: 'DEVICE_ID',
channel: 'CHANNEL_NAME', // The name of the channel, or undefined if version_id provided
version_id: 'VERSION_NAME' // this is optional, if provide it will override the channel, that useful when you want to debug only one user.
}, {
headers: {
authorization: 'YOUR_API_KEY' // choose a key with 'write' or 'all' rights
}
})
Cloudflare
addEventListener('fetch', (event) => {
event.respondWith(
handleRequest(event.request).catch(
err => new Response(err.stack, { status: 500 })
)
)
})
async function handleRequest(request) {
const { pathname, method } = new URL(request.url)
const body = await request.json()
const newBody = JSON.stringify({
app_id: 'YOUR_APP_ID',
device_id: body.device_id,
channel: 'alpha'
})
const newUrl = new URL('https://api.capgo.app/device')
const options = {
headers: {
authorization: 'YOUR_API_KEY',
},
method: 'POST',
body: newBody
}
if (request.method === 'DELETE') {
// DELETE the channel link
options.method = 'DELETE'
return fetch(newUrl.toString(), options)
}
return fetch(newUrl.toString(), options)
}
然后只需将设备_id发送到已部署的URL中,使用POST方法添加和DELETE方法删除。
在此配置后,请尝试在您的应用程序中添加一个按钮以选择频道,并在Web应用程序中检查是否已设置。
您还可以发送 null 为了移除覆盖
如果您需要程序性地检查设备上设置的覆盖版本,您可以在同一URL上获取
import axios from 'axios'
const res = await axios.get('https://api.capgo.app/device?app_id=YOUR_APP_ID&device_id=DEVICE_ID', {
headers: {
authorization: 'YOUR_API_KEY' // choose a key with 'write' or 'all' rights
}
})
console.log('data', res.json())
继续阅读《如何向单个用户或一组用户发送特定版本》
如果您正在使用 《如何向单个用户或一组用户发送特定版本》 为了规划频道路由和阶段性发布,连接它与 频道 频道 频道 频道 频道 频道 测试版体验解决方案 用于测试版体验解决方案中的产品工作流程,以及 版本定位解决方案 用于版本定位解决方案中的产品工作流程。