CodePush尝试

六月 06, 2018

1、热更新技术

1.2 cordova-android@6.2.3 实践步骤

cordova plugin add cordova-plugin-code-push@latest

注意:1.1.1版本中
由于 cordova-plugin-code-push的config.xml中
<hook type="before_plugin_install" src="scripts/beforeInstall.js" />
scripts/beforeInstall.js 路径配置有误, 应该是
<hook type="before_plugin_install" src="hooks/beforeInstall.js" />
导致一些包没下载到,需要手动下载一些包:
cordova plugin add cordova-plugin-file@3.0.0
cordova plugin add cordova-plugin-file-transfer@1.4.0
cordova plugin add cordova-plugin-zip

With the CodePush plugin installed, configure your app to use it via the following steps:

  1. Add your deployment keys to the config.xml file, making sure to include the right key for each Cordova platform:

    <platform name="android">
        <preference name="CodePushDeploymentKey" value="YOUR-ANDROID-DEPLOYMENT-KEY" />
    </platform>
    <platform name="ios">
        <preference name="CodePushDeploymentKey" value="YOUR-IOS-DEPLOYMENT-KEY" />
    </platform>
  2. If you’re using an <access origin="*" /> element in your config.xml file, then your app is already allowed to communicate with the CodePush servers and you can safely skip this step. Otherwise, add the following additional <access /> elements:

    <access origin="https://codepush.azurewebsites.net" />
    <access origin="https://codepush.blob.core.windows.net" />
    <access origin="https://codepushupdates.azureedge.net" />
  3. To ensure that your app can access the CodePush server on CSP-compliant platforms, add https://codepush.azurewebsites.net to the Content-Security-Policy meta tag in your index.html file:

    <meta http-equiv="Content-Security-Policy" content="default-src https://codepush.azurewebsites.net 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />
  4. 发布更新(两种方式)

    code-push release-cordova danger-android(项目名) android(平台) --description "gengxinceshi"
    code-push release danger-android(项目名) ./platforms/android/assets/www(位置) 1.0.0(对应版本) --description "测试"
    codePush.checkForUpdate(function (update) {
        if (!update) {
            console.log("The app is up to date.");
        } else {
            codePush.sync(null, {
                updateDialog: {
                    appendReleaseDescription: true, // 显示更新内容
                    descriptionPrefix: '更新内容:\n',
                    updateTitle: '版本更新',
                    optionalUpdateMessage : '有更新内容,请立刻执行更新!',
                    mandatoryUpdateMessage: "有更新内容,请立刻执行更新!",
                    optionalIgnoreButtonLabel: "忽略",
                    optionalInstallButtonLabel: "立即更新", // 可选更新时候的 按钮
                    mandatoryContinueButtonLabel: '立即更新',   // 强制更新时候的 按钮
                },
                installMode: InstallMode.IMMEDIATE
            });
        }
    });

命令使用

  1. 发布
    code-push release ElephantApp-ios ./ios-bundle/ 0.2.0 –d Production –description ‘新功能更新’ –mandatory true (强制更新)

  2. 清除历史部署记录
    code-push deployment clear Production or Staging

  3. 回滚
    code-push rollback Production –targetRelease v4(codepush服务部署的版本号)