跳过内容

在中国使用 Capgo

如果您正在将应用程序部署到中国用户,您需要配置Capgo以使用区域OST(对象存储技术)URL,以确保可靠和快速的更新。

为什么使用中国特定的URL?

标题:为什么使用中国特定的URL?

由于中国的网络基础设施和监管(长城防火墙),直接连接到国际服务器可能会很慢或不可靠。Capgo提供了专用的OST URL,数据位于香港,以最小化延迟并确保您的用户尽可能快和可靠地接收更新。

要为中国配置Capgo,您需要在Capacitor配置文件中设置三个特定的URL。这些URL指向Capgo的香港基础设施。

  1. 打开您的 capacitor.config.ts 文件

  2. 添加以下配置到 CapacitorUpdater 插件部分:

    import { CapacitorConfig } from '@capacitor/cli';
    const config: CapacitorConfig = {
    plugins: {
    CapacitorUpdater: {
    autoUpdate: 'atBackground',
    updateUrl: 'https://updater.capgo.com.cn/updates',
    statsUrl: 'https://updater.capgo.com.cn/stats',
    channelUrl: 'https://updater.capgo.com.cn/channel_self',
    },
    },
    };
    export default config;
  3. 重新构建您的应用以应用更改:

    终端窗口
    npm run build
    npx cap sync

配置详细信息

配置详细信息部分

以下是每个 URL 的作用:

  • updateUrl: https://updater.capgo.com.cn/updates - 用于检查并下载可用更新以更新您的应用
  • statsUrl: https://updater.capgo.com.cn/stats - 用于报告分析和使用统计信息回传到 Capgo
  • channelUrl: https://updater.capgo.com.cn/channel_self - 用于检索频道配置并确定哪些更新需要应用

增加 __CAPGO_KEEP_0__ 响应超时

Live Update更新器插件在Capgo时会中断API调用 responseTimeout 超过此值(值以秒为单位) 秒). Edge 架构在前端的Capgo也会处理大约 秒 视为某些路径的失败预算。

在中国大陆,跨境延迟往往更高。保持较高的 responseTimeout 因此插件有足够的空间完成更新检查和下载,而不是早期失败: updater.capgo.com.cn 复制到剪贴板

const config: CapacitorConfig = {
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
// Seconds. Raise above the default (20) for China network conditions.
responseTimeout: 60,
updateUrl: 'https://updater.capgo.com.cn/updates',
statsUrl: 'https://updater.capgo.com.cn/stats',
channelUrl: 'https://updater.capgo.com.cn/channel_self',
},
},
};

使用后台更新

标题:使用后台更新

我们 强烈建议使用 autoUpdate: 'atBackground' 中国的应用程序。中国的网络连接性较其他地区差,实时应用模式可能会导致用户体验不佳,如果下载被中断或缓慢。

相反,使用默认更新行为,更新在后台下载并在应用程序后台或重启时应用。这为您的用户提供了更可靠的体验。

const config: CapacitorConfig = {
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground', // Recommended for China
updateUrl: 'https://updater.capgo.com.cn/updates',
statsUrl: 'https://updater.capgo.com.cn/stats',
channelUrl: 'https://updater.capgo.com.cn/channel_self',
},
},
};

以下是中国地区应用推荐配置示例:

import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'My App',
webDir: 'dist',
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground', // Recommended for better reliability in China
responseTimeout: 60, // Seconds — give China network more room
updateUrl: 'https://updater.capgo.com.cn/updates',
statsUrl: 'https://updater.capgo.com.cn/stats',
channelUrl: 'https://updater.capgo.com.cn/channel_self',
},
},
};
export default config;

配置了中国特定的URL后,您可以验证更新是否正常工作:

  1. 上传一个新的包到Capgo:

    终端窗口
    npx @capgo/cli@latest bundle upload --channel=production
  2. 在中国测试设备上安装您的应用

  3. 监控更新过程:

    终端窗口
    npx @capgo/cli@latest app debug
  4. 检查更新是否从中国OST URL下载

标题:多区域部署

多区域部署

使用全球中国域名 updater.capgo.com.cn 使用全球中国域名

多区域部署

使用全球域名

中国域名 URL 对多区域应用工作无缝:

const config: CapacitorConfig = {
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground', // Recommended for China users
updateUrl: 'https://updater.capgo.com.cn/updates',
statsUrl: 'https://updater.capgo.com.cn/stats',
channelUrl: 'https://updater.capgo.com.cn/channel_self',
},
},
};

此单个配置将适用于:

  • 中国大陆地区的用户(使用香港基础设施)
  • 非中国地区的用户(通过阿里巴巴 DNS 访问相同的基础设施)

性能考虑:

虽然 .cn 域名通过阿里巴巴 DNS 在全球解析,适用于所有地区,但在中国外的用户相对于标准域名(api.capgo.app), which is resolved directly by Cloudflare where our backend is hosted. However, DNS resolution is fast, so the performance difference is minimal and won’t significantly impact the user experience.

如果您希望针对每个地区进行优化,可以考虑以下选项:

  • 为每个地区构建不同的应用程序版本并使用不同的配置
  • 使用环境配置动态设置URL
  • 为不同地区创建不同的发布频道

如果您需要帮助进行多地区部署策略,请联系我们至 support@capgo.app 或加入我们的 Discord 社区 zh-hans

/zh/docs/live-updates/china-configuration/

Live Update

您可以在这里监控Capgo的中国特定端点的健康状况和状态 status.capgo.com.cnGitHub

Capgo

code

API

  1. SDK CLI capacitor.config.ts
  2. npm responseTimeout - 使用至少 60 - 在中国使用秒钟以免更新请求还在飞行时插件中断
  3. - 检查网络连接 - 确保您的设备可以访问 updater.capgo.com.cn - 域名
  4. - 检查中国状态页面 - 检查 - 状态.capgo.com.cn - 查看是否有任何正在进行中的事件或性能下降
  5. - 查看日志 - 使用 npx @capgo/cli@latest app debug - 来检查错误消息
  6. 测试更新 测试更新
  7. - 试试上传一个新的捆绑包并监控下载过程 联系支持 support@capgo.app - 如果问题持续存在,请联系我们 support@__CAPGO_KEEP_0__.app 或加入我们的

下一步

下一步
  • 了解 更新行为 自定义更新时应用的方式
  • 探索 频道 管理不同发布轨迹
  • 查看 加密 确保您的更新安全

继续使用 Capgo 在中国

继续使用 Capgo 在中国

如果您正在使用 使用 Capgo 在中国 与 live update Live Updates Capgo 实时更新 为 Capgo Live Updates 概述 概述 功能 功能 更新行为 为更新行为的实现细节 更新类型 为更新类型的实现细节