native react 更新机制_react-native-code-push热更新

  • 创建³³ React-Native项目
 react-native init dounineApp
  • 安装code-push-cli
 npm install -g code-push-cli
  • 注册code-push帐号
code-push register 
Please login to Mobile Center in the browser window we've just opened.  Enter your token from the browser: 
#会弹出一个浏览器,让你注册,可以使用github帐号对其进行授权,授权成功会给一串Token,点击复制,在控制进行粘贴回车(或者使用code-push login命令)。 
Enter your token from the browser:  b0c9ba1f91dd232xxxxxxxxxxxxxxxxx 
#成功提示如下方 
Successfully logged-in. Your session file was written to /Users/huanghuanlai/.code-pus

342124816c1aed9ea71ec8a62aaa8b2e.png
  • code-push添加一个IOS的应用
 code-push app add dounineApp-ios ios react-native 
#成功提示如下方 Successfully added the "dounineApp-ios" app, along with the following default deployments: 
┌────────────┬──────────────────────────────────────────────────────────────────┐ 
│ Name       │ Deployment Key                                                   │ 
├────────────┼──────────────────────────────────────────────────────────────────┤ 
│ Production │ yMAPMAjXpfXoTfxCd0Su9c4-U4lU6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │ 
├────────────┼──────────────────────────────────────────────────────────────────┤
 │ Staging    │ IjC3_iRGEZE8-9ikmBZ4ITJTz9wn6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │ └────────────┴────────────────────────
──────────────────────────────────────────┘
  • 在继续code-push添加一个机器人的应用
 code-push app add dounineApp-android android react-native 
#成功提示如下方 Successfully added the "dounineApp-android" app, along with the following default deployments: 
┌────────────┬──────────────────────────────────────────────────────────────────┐
│ Name       │ Deployment Key                                                   │ ├────────────┼────────────────────────
──────────────────────────────────────────┤
 │ Production │ PZVCGLlVW-0FtdoCF-3ZDWLcX58L6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │ 
├────────────┼──────────────────────────────────────────────────────────────────┤
 │ Staging    │ T0NshYi9X8nRkIe_cIRZGbAut90a6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │ └────────────┴────────────────────────
──────────────────────────────────────────┘
 
  • 在项目根目录添加react-native-code-push
 npm install react-native-code-push --save #或者 yarn add react-native-code-push
  • 链接react-native-code-push
react-native link
Scanning folders for symlinks in /Users/huanghuanlai/dounine/oschina/dounineApp/node_modules (8ms)
? What is your CodePush deployment key for Android (hit <ENTER> to ignore) T0NshYi9X8nRkIe_cIRZGbAut90a6dec4087-57cf-4c9d-b0dc-ad38ce431e1d

#将刚才添加的Android App的Deployment Key复制粘贴到这里,复制名为Staging测试Deployment Key。

rnpm-install info Linking react-native-code-push android dependency
rnpm-install info Android module react-native-code-push has been successfully linked
rnpm-install info Linking react-native-code-push ios dependency
rnpm-install WARN ERRGROUP Group 'Frameworks' does not exist in your Xcode project. We have created it automatically for you.
rnpm-install info iOS module react-native-code-push has been successfully linked
Running ios postlink script
? What is your CodePush deployment key for iOS (hit <ENTER> to ignore) IjC3_iRGEZE8-9ikmBZ4ITJTz9wn6dec4087-57cf-4c9d-b0dc-ad38ce431e1d

#继续复制Ios的Deployment Key

Running android postlink script
  • react-nativeApp.js文件添加自动更新代码
import codePush from "react-native-code-push";
const codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };
export default class App extends Component<{}> {

  componentDidMount(){
    codePush.sync({
      updateDialog: true,
      installMode: codePush.InstallMode.IMMEDIATE,
      mandatoryInstallMode:codePush.InstallMode.IMMEDIATE,
      //deploymentKey为刚才生成的,打包哪个平台的App就使用哪个Key,这里用IOS的打包测试
      deploymentKey: 'IjC3_iRGEZE8-9ikmBZ4ITJTz9wn6dec4087-57cf-4c9d-b0dc-ad38ce431e1d',
      });
  }
  ...
安卓发布
 1.修改App.js的deploymentKey为安卓的
 deploymentKey:'T0NshYi9X8nRkIe_cIRZGbAut90a6dec4087-57cf-4c9d-b0dc-ad38ce431e1d'
 2.运行
 react-native run-android
 3.发布
 code-push release-react dounineApp-android android


作者:kikiki2
链接:https://www.jianshu.com/p/6dadcc27cef1
来源:简书

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值