跳过内容

使用 Capgo 在中国

If you’re deploying your app to users in China, you’ll need to configure Capgo to use regional OST (Object Storage Technology) URLs to ensure reliable and fast updates.

Due to network infrastructure and regulations in China (the Great Firewall), direct connections to international servers can be slow or unreliable. Capgo provides dedicated OST URLs with data located in Hong Kong to minimize latency and ensure your users receive updates as quickly and reliably as possible.

To configure Capgo for China, you need to set three specific URLs in your Capacitor configuration file. These URLs point to Capgo’s Hong Kong-based infrastructure.

  1. Open your 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 - 用于检查并下载可用更新的应用程序
  • 统计数据URL: https://updater.capgo.com.cn/stats - 用于将分析和使用统计数据发送回 Capgo
  • 频道URL: 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
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',
},
},
};

This single configuration will work for:

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

性能考虑:

虽然 .cn 域名通过阿里巴巴 DNS 全球解析并且在所有地方都有效,但对于非中国地区用户来说,使用此域名的性能稍微低于标准域名(api.capgo.app),因为标准域名直接由Cloudflare解析,而我们的后端位于此处。然而,DNS 解析速度快,性能差异很小,通常不会对用户体验产生重大影响。

备选方案:区域特定配置

Alternative: Region-Specific Configurations

如果您更喜欢为每个区域优化不同,请也可以考虑:

  • 为每个区域构建不同的应用程序变体
  • 使用环境配置动态设置 URL
  • 为不同区域创建不同的发布渠道

如果您需要帮助解决多区域部署策略,请联系我们在 support@capgo.app 或加入我们的 Discord 社区 获取帮助

Troubleshooting

故障排除

如果您在中国遇到更新问题:

  1. 验证您的配置 - 确认您的所有三个 URL 地址是否正确设置在您的 capacitor.config.ts
  2. 检查网络连接 - 确保您的设备可以访问 updater.capgo.com.cn 域名
  3. 查看日志 - 使用 npx @capgo/cli@latest app debug 来检查错误消息
  4. 测试更新 - 尝试上传一个新包并监控下载过程
  5. 联系支持 - 如果问题持续存在,请联系我们在 support@capgo.app 或加入我们的 Discord 社区 获取帮助

标题为“下一步”

section
  • 了解更多 更新行为 自定义更新时机
  • 探索 频道 管理不同发布轨迹
  • 查看 加密 确保您的更新安全

继续使用Capgo在中国

继续使用Capgo在中国

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