RN:热更新

2023-03-26  本文已影响0人  春暖花已开
准备工作:
  • 1、在 AppCenter 注册账号等,创建应用;
  • 安装 react-native-code-push,之后执行 pod install
一、Android的配置:

参考:Android Setup

二、iOS的配置:

参考:iOS Setup

三、RN的配置:

参考:React Native Client SDK Plugin Usage

四、发布更新:

一般为了方便操作,通常使用 appcenter codepush release-react 命令来发布更新。

appcenter codepush release-react
[--use-hermes]
[--extra-hermes-flag <arg>]
[--extra-bundler-option <arg>]
[-t|--target-binary-version <arg>]
[-o|--output-dir <arg>]
[--sourcemap-output-dir <arg>]
[-s|--sourcemap-output <arg>]
[-xt|--xcode-target-name <arg>]
[-c|--build-configuration-name <arg>]
[--plist-file-prefix <arg>]
[-xp|--xcode-project-file <arg>]
[-p|--plist-file <arg>]
[--pod-file <arg>]
[-g|--gradle-file <arg>]
[-e|--entry-file <arg>]
[--development]
[-b|--bundle-name <arg>]
[-r|--rollout <arg>]
[--disable-duplicate-release-error]
[-k|--private-key-path <arg>]
[-m|--mandatory]
[-x|--disabled]
[--description <arg>]
[-d|--deployment-name <arg>]
[-a|--app <arg>]

其中参数:
-a|--app <arg>:格式为<ownerName>/<appName>;
-b|--bundle-name <arg>:生成的JS包文件的名称。如果未指定,则将使用标准bundle名称:"main.jsbundle" (iOS)、 "index.android.bundle" (Android) 、"index.windows.bundle" (Windows) ;
-d|--deployment-name <arg>:将更新发布到的部署,默认Staging;
--description <arg>:描述在此版本中对应用程序所做的更改;
--development:指定是否生成 dev 或 release 版本;
-e|--entry-file <arg> :应用程序入口JavaScript文件的路径。如果省略, "index.<platform>.js"、 "index.js"将被使用;
-m|--mandatory:是否强制更新;
-r|--rollout <arg>:能收到此版本的用户百分比;-x|--disabled:此版本是否立即可下载;
-t|--target-binary-version <arg>:指定此版本的二进制应用程序版本的Semver表达式(例如1.1.0,~1.2.3);
-xt|--xcode-target-name <arg> :目标名称(PBXNativeTarget),仅限iOS;

如:

appcenter codepush release-react -a org/projectName-android -d Staging -m -t 1.0.0 --description '大家好,为了更好的服务您,我们需要升级服务'

说明:以下等两条命令是等效

appcenter codepush release-react -a <ownerName>/MyApp-iOS

等同于

mkdir ./CodePush

react-native bundle --platform ios \
--entry-file index.ios.js \
--bundle-output ./CodePush/main.jsbundle \
--assets-dest ./CodePush \
--dev false

appcenter codepush release -a <ownerName>/MyApp-iOS -c ./CodePush -t 1.0.0
五、封装提示
import CodePush from 'react-native-code-push'

export const update = component =>
  CodePush({
    updateDialog: {
      appendReleaseDescription: true,
      descriptionPrefix: '更新内容:',
      mandatoryContinueButtonLabel: '立即更新',
      mandatoryUpdateMessage: '',
      optionalIgnoreButtonLabel: '稍后',
      optionalInstallButtonLabel: '后台更新',
      optionalUpdateMessage: '',
      title: '更新提示'
    }
  })(component)

export default update

参考:

code-push

上一篇 下一篇

猜你喜欢

热点阅读