ReactNative系列之十八codepush热更新

目前仅针对Android,iOS后续再补

1、简介

codepush是微软的一套热升级解决实现,还有一种是reactnatie中文网上的react-native-pushy。这两种方案我都试了下,推荐使用codepush, codepush在github上看文档感觉很麻烦,其实真的很好用,就是有时候慢,不过自己code push server呗!react-native-pushy用了下,各种问题。不说了~


2、codepush使用

1)首先需要在 code push注册一个帐号,这个不多说了,有可能会有网速问题。翻墙!

2)集成

#1、参考https://github.com/Microsoft/react-native-code-push, 找到对应版本的安装

npm install --save react-native-code-push@2.XXX
react-native link react-native-code-push
#2、在JS中添加代码

import codePush from "react-native-code-push";
        // codepush
        codePush.sync({
            installMode: codePush.InstallMode.ON_NEXT_RESUME,//启动模式三种:ON_NEXT_RESUME、ON_NEXT_RESTART、IMMEDIATE
            updateDialog: {

                appendReleaseDescription:true,//是否显示更新description,默认为false

                descriptionPrefix:"更新内容:",//更新说明的前缀。 默认是” Description:

                mandatoryContinueButtonLabel:"立即更新",//强制更新的按钮文字,默认为continue

                mandatoryUpdateMessage:"",//- 强制更新时,更新通知. Defaults to “An update is available that must be installed.”.

                optionalIgnoreButtonLabel: '稍后',//非强制更新时,取消按钮文字,默认是ignore

                optionalInstallButtonLabel: '后台更新',//非强制更新时,确认文字. Defaults to “Install”

                optionalUpdateMessage: '有新版本了,是否更新?',//非强制更新时,更新通知. Defaults to “An update is available. Would you like to install it?”.

                title: '更新提示'//要显示的更新通知的标题. Defaults to “Update available”.

            },



#3、设置Java代码,在Application中设置key(key是在codepush创建应用时,获取到的), 注意是下面的第一个参数

new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG),

#4、常用命令

$ cd /path/to/code-push-demo-app
$ npm install
$ cd android
$ ./gradlew assembleRelease
$ cd app/build/outputs/apk #install app-release.apk into your phone
$ code-push login http://api.code-push.com:8080 #登录code-push-server
$ code-push app add CodePushReactNativeDemo-ios  #iOS版
$ code-push app add CodePushReactNativeDemo-android #android版
$ cd /path/to/code-push-demo-app
$ npm install
$ code-push release-react CodePushReactNativeDemo-ios ios -d Production #发布到code-push-server ios
$ code-push release-react CodePushReactNativeDemo-android android -d Production #发布code-push-server android
code-push release-react bus-android android -d Production --des "修复了一些bugs" -m false
效果图如下: 枣庄智行公交,用ReactNative写的,大家可以体验下效果


3、参考其它links, 感谢

http://blog.csdn.net/sinat_17775997/article/details/53894030  

React Native如何使用 code-push 热更新


https://github.com/lisong/code-push-demo-app

https://github.com/Microsoft/react-native-code-push

http://www.jianshu.com/p/9e3b4a133bcc react native codepush热更新解决成功更新

http://www.jianshu.com/p/eb7fdee307dc react native codepush之搭建自己的更新服务器

http://blog.csdn.net/h254532699/article/details/54382162 code-push-server 搭建自己的推送服务器流程

http://blog.csdn.net/oiken/article/details/50279871    

使用CodePush热更新ReactNative JS代码


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值