跳过主要内容
迁移

从 App Center 迁移到 Capgo

在本指南中,我们将逐步完成从 Capgo Live Updates 到 Microsoft CodePush 的迁移。

马丁·多纳迪尤

马丁·多纳迪尤

内容营销人员

从 App Center 迁移到 Capgo

迁移摘要

  • Capgo 帮助开发团队将实时应用部署到已部署应用的服务。
  • Capacitor 使用 jQuery Mobile、Framework 7、Sencha、KendoUI、Ionic 或自定义解决方案编写的 JavaScript 应用都可以迁移。.
  • 不需要现有 Ionic 应用。 Colt
为 App Center Build 提供等效服务(构建 Android/iOS 应用)。

测试、诊断和分析服务。 migrate to Capacitor first before migrating to Capgo.

先迁移到 Capacitor 再迁移到 Capacitor。

幸运的是,迁移过程很容易,大多数Cordova插件与Capacitor兼容。 开始迁移.

关于Capgo

Capgo处理应用程序随时间的更新。开发团队可以专注于应用程序的独特功能,并将复杂的应用程序交付过程外包给Capgo。

Capgo填补了Web交付和移动之间的空白。

Capgo的先决条件

像App Center一样 Capgo 支持在Azure DevOps、Bitbucket、GitHub和GitLab上的Git存储库中托管的应用程序。

安装Capgo CLI

注意

在开始之前,您需要在计算机上安装Node和NPM。始终使用 当前 LTS 版本 Capgo 不要使用旧版本。

创建 package.json 并 Capacitor 配置文件

注意

在开始之前,我建议在一个新的 Git Branch 上进行更改。

由于 Capgo 是用来自动化 capacitor 应用程序的,因此它需要一个文件,这可能是您的应用程序没有的。首先,创建一个 capacitor.config.json 文件。创建它的最简单方法是在应用程序的根目录中运行:

npm install @capacitor/core

然后,使用 CLI 问卷初始化 Capacitor:

npx cap init

CLI 将会问您一些问题,包括应用程序名称和您希望为应用程序使用的包 ID。

最后,提交新文件到您的项目:

git add .git commit -m "added package json and capacitor config" && git push

迁移的Code

现在您已经将新要求的文件放在那里,您可以将注意力转移到实际应用本身。 Capgo 应用程序本身的实际内容。 Capgo 期望整个构建的应用程序位于一个名为__CAPGO_KEEP_0__的目录内。 dist.

如果您的构建code不在一个目录内,请在code配置文件中更改此值。 dist directory, change this value in the Capacitor config file.

应用程序结构

__CAPGO_KEEP_0__配置

Capgo

在您的应用程序准备好 Capgo 集成后,时刻签署并获取您的API密钥以上传您的第一版!首先, 注册Capgo账户.

一旦您登录Capgo,请导航到帐户页面,然后点击API密钥,最后点击“写”键以将其复制到剪贴板中。

安装CapgoSDK

从命令行直接进入您的Capacitor应用程序文件夹根目录,运行以下命令:

npm i @capgo/capacitor-updater && npx cap sync 将插件安装到您的Capacitor应用程序中。

然后将code添加到您的应用程序中,取代CodePush:

import { CapacitorUpdater } from '@capgo/capacitor-updater'

CapacitorUpdater.notifyAppReady()

这将告诉本机插件安装成功。

实时更新(CodePush替代品)

实时更新功能通过使用已安装的功能来工作 Capgo SDK 在您的原生应用程序中监听特定部署通道目的地。 当一个 Web 构建被 assignment 到一个通道目的地时,更新将会被部署到运行配置为监听指定通道目的地的二进制文件的用户设备中。

登录到 Capgo CLOUD

首先,使用 all apikey 在您的帐户中存在的帐户来登录 CLI:

npx @capgo/cli@latest login YOURKEY

添加您的第一个应用

让我们从创建应用程序开始,使用 Capgo Cloud 和 CLI。

npx @capgo/cli@latest app add

此命令将使用 Capacitor 配置文件中定义的所有变量来创建应用程序。

上传您的第一个捆绑包

运行命令来构建您的 code 并将其发送到 Capgo:

npx @capgo/cli@latest bundle upload --channel production

默认情况下,版本名称将是您的 package.json 文件.

检查入 Capgo 如果构建存在.

您甚至可以使用我的移动沙盒应用测试它. 设置默认渠道.

您已经将应用发送到__CAPGO_KEEP_0__后,需要将您的渠道设置为

让应用从Capgo接收更新. default to let apps receive updates from Capgo.

npx @capgo/cli@latest channel set production -s default

将此配置添加到主JavaScript文件.

然后执行

import { CapacitorUpdater } from '@capgo/capacitor-updater'

CapacitorUpdater.notifyAppReady()

然后执行 npm run build && npx cap copy To update your app.

在设备上接收实时更新

为了让您的应用程序从 Deploy 接收实时更新,您需要在设备或模拟器上运行应用程序。使用以下命令启动本地应用程序在模拟器或连接到计算机的设备上运行是最简单的方法。

npx cap run [ios | android]

打开应用程序,放到后台,然后再次打开应用程序,您应该在日志中看到应用程序已经更新。

恭喜! 🎉 您成功部署了第一个实时更新。这只是您可以使用实时更新的开始。要了解更多信息,请查看完整的 实时更新文档.

移除 App Center 依赖项

现在我们已经集成了 Capgo 的服务,您应该移除任何 App Center 的引用。除了移除未使用的 code/services 是最佳实践外,移除 SDK 还可以减少应用程序的大小。

首先,打开终端,然后卸载 App Center 插件:

    cordova plugin remove cordova-plugin-appcenter-analytics cordova-plugin-appcenter-crashes cordova-plugin-code-push

接下来,打开 config.xml 并移除以下 preference 值。它们将类似于:

    <preference name="APP_SECRET" value="0000-0000-0000-0000-000000000000" /><preference name="CodePushDeploymentKey" value="YOUR-ANDROID-DEPLOYMENT-KEY" /><preference name="CodePushPublicKey" value="YOUR-PUBLIC-KEY" />

If you were using App Center Analytics in your app, remove the following preferences elements: APPCENTER_ANALYTICS_ENABLE_IN_JS and APPCENTER_CRASHES_ALWAYS_SEND.

Remove the following <access /> elements:

    <access origin="https://codepush.appcenter.ms" /><access origin="https://codepush.blob.core.windows.net" /><access origin="https://codepushupdates.azureedge.net" />

Remove the reference to CodePush in the CSP meta tag in the index.html file (https://codepush.appcenter.ms):

    <meta http-equiv="Content-Security-Policy" content="default-src https://codepush.appcenter.ms 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />

Finally, within your app, remove any code references to App Center services, such as codePush.sync();.

Next Steps

You’ve migrated from App Center to Capgo, utilizing the Live Updates. This is just the beginning of what you can use Capgo for. Explore the rest of the service includes Channel (multiple environments) and override. Cloud CLI integration, use Capgo inside your CI/CD platform of choice (such as GitHub Action, GitLab, Jenkins, and more).

Automatic send app update

如果您的code托管在GitHub上,您可以在几个步骤内设置自动构建和发布,感谢GitHub动作。

我已经写了第二篇文章,允许您这样做。

致谢

感谢 Ionic,这篇文章基于 这篇文章 使用chat-gpt-3重写并适应。

从App Center迁移到Capgo

如果您正在使用 从App Center迁移到Capgo 来规划迁移和企业运营,连接它 Capgo 企业版 为Capgo 企业版中的产品工作流程 Ionic 企业插件替代品 为Ionic 企业插件替代品中的产品工作流程 Capgo 替代品 为Capgo 替代品中的产品工作流程 Capgo 咨询 为Capgo 咨询中的产品工作流程和 Capgo 高级支持 为Capgo 高级支持中的产品工作流程。

Live updates for Capacitor apps

When a web-layer bug is live, ship the fix through Capgo instead of waiting days for app store approval. Users get the update in the background while native changes stay in the normal review path.

立即开始

最新博客

Capgo gives you the best insights you need to create a truly professional mobile app.