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

然后在您的Ionic应用程序的 code 中添加此项,为了获得最佳体验,请在用户点击“注册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 role, for example.
Then Go to the Web app or native app Capgo, connect as app admin, select your app, click on the device list.
Then put in the search bar the deviceID click on the one found and then click on the Channel link choose the development, ask your teammate to open the app again, wait 30 sec and open close.
He should get your version.
Automatic way
This can be useful for your beta testers, this is longer to implement.
Same as the manual way, you have to get the deviceID
import { CapacitorUpdater } from '@capgo/capacitor-updater'
const deviceId = await CapacitorUpdater.getDeviceId()
But this time you have to send it automatically to your backend, I let you decide how you do that.
I will just suggest you to store it in a database, that will facilitate your life later.
Then in your backend you have to send it to Capgo backend too. Below two code examples:
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 以删除覆盖
如果您需要程序matic地检查设备上的覆盖设置,请在同一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())
继续阅读如何向单个用户或组发送特定更新
如果您正在使用 继续阅读如何向单个用户或组发送特定更新 以计划频道路由和阶段性发布,连接它与 频道 查看频道的实现细节 频道 关于频道的实施细节,请参见 频道 关于频道的实施细节,请参见 Beta 测试解决方案 了解 Beta 测试解决方案的产品工作流程 版本目标解决方案 了解版本目标解决方案的产品工作流程