ReactNative系列之十八codepush热更新

来源:互联网 发布:ubuntu 12.04 qq 编辑:程序博客网 时间:2024/04/30 04:38

目前仅针对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.XXXreact-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/54382162code-push-server 搭建自己的推送服务器流程

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

使用CodePush热更新ReactNative JS代码


原创粉丝点击