capacitor-plugin-codepush
v6.0.1
Published
web hot replace
Readme
capacitor-plugin-codepush
web hot replace
server base on code-push-server
大版本跟@capacitor
v6.x support
Capacitor 6
Getting Started
With the Capacitor plugin installed, configure your app to use it via the following steps:
Add your deployment & code signing (optional) keys to the
capacitor.config.jsonfile, making sure to include the right key:"Plugins": { ... (other plugins) "CodePush": { "IOS_DEPLOY_KEY": "IOS_DEPLOYMENT_KEY", "IOS_PUBLIC_KEY": "APP_SECRET_KEY", "ANDROID_DEPLOY_KEY": "ANDROID_DEPLOYMENT_KEY", "ANDROID_PUBLIC_KEY": "APP_SECRET_KEY", "SERVER_URL": "https://codepush.appcenter.ms/" } }As a reminder, the deployment keys are generated for you when you created your CodePush app via the CLI. If you need to retrieve them, you can simply run
appcenter codepush deployment list --app <ownerName>/<appName> --displayKeys, and grab the key for the specific deployment you want to use (e.g.Staging,Production). App IDs can be retrieved by runningappcenter apps list.The public keys should be generated by you, as should the corresponding private keys.
# generate private RSA key and write it to private.pem file openssl genrsa -out private.pem # export public key from private.pem into public.pem openssl rsa -pubout -in private.pem -out public.pemNOTE: You must create a separate CodePush app for iOS and Android, which is why the above sample illustrates declaring separate keys for Android and iOS. If you're only developing for a single platform, then you only need to specify the deployment key for either Android or iOS.
To ensure that your app can access the CodePush server on CSP-compliant platforms, add
https://codepush.appcenter.msto theContent-Security-Policymetatag in yourindex.htmlfile:<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 *" />
Install
npm install capacitor-plugin-codepush
npx cap syncimport { CodePush } from 'capacitor-plugin-codepush';
import { Plugins, AppState } from '@capacitor/core';
CodePush.sync();
const { App } = Plugins;
App.addListener('appStateChange', (state: AppState) => {
// state.isActive contains the active state
if (state.isActive) {
codePush.sync();
}
});// cli本地部署只支持到2.1.9
npm i -g [email protected]
// 登录,获取key
code-push login https://code-push.xxx.cn/
//给app在热更新服务器上创建应用
code-push app add <appName> <os> <platform>
//删除应用
code-push app rm <appName>
//查看热更新服务器上有哪些应用
code-push app list
//发布应用
code-push release-cordova <appName> <platform> [options]
Options参数:
--deploymentName, -d ..指定部署的类型.默认"Staging",可以选择"Production"或其他 自定义类型
--description, --des ..添加描述
--mandatory, -m .......指定此版本是否为强制更新版本
例1:发布更新
code-push release-cordova ionic2_tabs_android android --des ""
例2:部署"Production"状态的更新,即生产环境的热更新部署使用这句命令
code-push release-cordova ionic2_tabs_android android -d "Production" --des ""
注意:一般生产环境的app是压缩过的,所以在发布正式环境热更新之前,先执行"ionic build --prod"压缩代码
例3:部署ios应用的更新
code-push release-cordova ionic2_tabs_ios ios --des ""
例4:添加-m参数强制更新,code-push插件从服务端下载完代码,会立即自动重启app
code-push release-cordova ionic2_tabs_android android -m --des ""
//查看部署状态
code-push deployment list <appName>
例1:
code-push deployment list ionic2_tabs_android
例2:查看部署状态及key值,忘记key就这样找
code-push deployment list ionic2_tabs_android -k
//清空部署记录
code-push deployment clear <appName> <deploymentName>
如:清空Staging状态的部署记录
code-push deployment clear ionic2_tabs_android Staging
//添加部署状态,默认只有"Staging"和"Production"两中状态
code-push deployment add <appName> [deploymentName]
//删除自定义的部署状态
code-push deployment rm <appName> <deploymentName>
API
getDeploymentKey()getServerURL()getPublicKey()decodeSignature(...)getBinaryHash()getPackageHash(...)notifyApplicationReady()isFirstRun(...)isPendingUpdate()isFailedUpdate(...)install(...)reportFailed(...)reportSucceeded(...)restartApplication()preInstall(...)getAppVersion()getNativeBuildTime()unzip(...)addListener('codePushStatus', ...)- Interfaces
getDeploymentKey()
getDeploymentKey() => any获取deployment key
Returns: any
getServerURL()
getServerURL() => any获取服务器url
Returns: any
getPublicKey()
getPublicKey() => any获取public key
Returns: any
decodeSignature(...)
decodeSignature(options: NativeDecodeSignatureOptions) => any解密签名
| Param | Type |
| ------------- | ------------------------------------------------------------------------------------- |
| options | NativeDecodeSignatureOptions |
Returns: any
getBinaryHash()
getBinaryHash() => anyReturns: any
getPackageHash(...)
getPackageHash(options: NativePathOptions) => any| Param | Type |
| ------------- | --------------------------------------------------------------- |
| options | NativePathOptions |
Returns: any
notifyApplicationReady()
notifyApplicationReady() => anyReturns: any
isFirstRun(...)
isFirstRun(options: NativeHashOptions) => any| Param | Type |
| ------------- | --------------------------------------------------------------- |
| options | NativeHashOptions |
Returns: any
isPendingUpdate()
isPendingUpdate() => anyReturns: any
isFailedUpdate(...)
isFailedUpdate(options: NativeHashOptions) => any获取失败的更新
| Param | Type |
| ------------- | --------------------------------------------------------------- |
| options | NativeHashOptions |
Returns: any
install(...)
install(options: NativeInstallOptions) => any安装更新
| Param | Type |
| ------------- | --------------------------------------------------------------------- |
| options | NativeInstallOptions |
Returns: any
reportFailed(...)
reportFailed(options: NativeStatusReportOptions) => any报告失败
| Param | Type |
| ------------- | ------------------------------------------------------------------------------- |
| options | NativeStatusReportOptions |
Returns: any
reportSucceeded(...)
reportSucceeded(options: NativeStatusReportOptions) => any报告成功
| Param | Type |
| ------------- | ------------------------------------------------------------------------------- |
| options | NativeStatusReportOptions |
Returns: any
restartApplication()
restartApplication() => any重启应用
Returns: any
preInstall(...)
preInstall(options: NativeInstallOptions) => any安装前校验
| Param | Type |
| ------------- | --------------------------------------------------------------------- |
| options | NativeInstallOptions |
Returns: any
getAppVersion()
getAppVersion() => any获取版本
Returns: any
getNativeBuildTime()
getNativeBuildTime() => any获取构建时间
Returns: any
unzip(...)
unzip(options: NativeUnzipOptions) => any解压文件
| Param | Type |
| ------------- | ----------------------------------------------------------------- |
| options | NativeUnzipOptions |
Returns: any
addListener('codePushStatus', ...)
addListener(eventName: "codePushStatus", listenerFunc: (info: any) => void) => voidcodepush过程监听
| Param | Type |
| ------------------ | ----------------------------------- |
| eventName | 'codePushStatus' |
| listenerFunc | (info: any) => void |
Interfaces
PluginCallResponse
| Prop | Type |
| ----------- | -------------- |
| value | T |
NativeDecodeSignatureOptions
| Prop | Type |
| --------------- | ------------------- |
| publicKey | string |
| signature | string |
NativePathOptions
| Prop | Type |
| ---------- | ------------------- |
| path | string |
NativeHashOptions
| Prop | Type |
| ----------------- | ------------------- |
| packageHash | string |
NativeInstallOptions
| Prop | Type |
| ------------------- | ------------------- |
| startLocation | string |
NativeStatusReportOptions
| Prop | Type |
| ------------------ | ----------------------------------------------------- |
| statusReport | StatusReport |
StatusReport
| Prop | Type |
| ---------------------------------- | ------------------- |
| status | number |
| label | string |
| appVersion | string |
| deploymentKey | string |
| lastVersionLabelOrAppVersion | string |
| lastVersionDeploymentKey | string |
NativeUnzipOptions
| Prop | Type |
| --------------------- | ------------------- |
| zipFile | string |
| targetDirectory | string |
