CodePush 热更新ReactNative之React Native Client SDK
来源:互联网 发布:同花顺mac版视频 编辑:程序博客网 时间:2024/05/17 03:45
目前用的RN版本都是大于0.30的所以一般用最新的codePush
安装
1. 前往目录下安装 npm install --save react-native-code-push@latest
2. 安装,推荐使用 rnpm link react-native-code-push
若未安装rnpm 使用npm i -g rnpm
安装
3. 配置(iOS)
- 在AppDelegate.m中加入头文件
#import "CodePush.h"
- 用
jsCodeLocation = [CodePush bundleURL];
替换其他的jsCodeLocation
- 更改Info.plist ,在里面增加
CodePushDeploymentKey
从新建的codePush中获取到开发环境的key;可以用这个显示keycode-push deployment ls <appName> -k
- 配置(安装)
- 在
MainApplication.java
中加入修改
// 1. Import the plugin class.import com.microsoft.codepush.react.CodePush;public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ... // 2. Override the getJSBundleFile method in order to let // the CodePush runtime determine where to get the JS // bundle location from on each app start @Override protected String getJSBundleFile() { return CodePush.getJSBundleFile(); } @Override protected List<ReactPackage> getPackages() { // 3. Instantiate an instance of the CodePush runtime and add it to the list of // existing packages, specifying the right deployment key. If you don't already // have it, you can run "code-push deployment ls <appName> -k" to retrieve your key. return Arrays.<ReactPackage>asList( new MainReactPackage(), new CodePush("deployment-key-here", MainApplication.this, BuildConfig.DEBUG) ); } };}
5.发布版本包
//基本不会出错的方法code-push release-react <appName> <platform>code-push release-react MyApp ioscode-push release-react MyApp-Android android
自己定义的版本发布
# Release a mandatory update with a changelog//发布强制性升级的包,并添加描述code-push release-react MyApp ios -m --description "Modified the header color"# Release an update for an app that uses a non-standard entry file name, and also capture# the sourcemap file generated by react-native bundlecode-push release-react MyApp ios --entryFile MyApp.js --sourcemapOutput ../maps/MyApp.map# Release a dev Android build to just 1/4 of your end userscode-push release-react MyApp-Android android --rollout 25% --dev true# Release an update that targets users running any 1.1.* binary, as opposed to# limiting the update to exact version name in the build.gradle filecode-push release-react MyApp-Android android --targetBinaryVersion "~1.1.0"
6.JavaScript中代码
//导入文件import codePush from "react-native-code-push";//设置检查更新的方法-开启检查更新let CodePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_START };class MyApp extends Component {render (){}componentDidMount() { codePush.sync({ updateDialog: false,//检查更新,不弹出提示 installMode: codePush.InstallMode.ON_NEXT_RESUME//更新模式,下一次进入 }); //如果你期望更及时的获得更新,可以在每次APP从后台进入前台的时候去主动的检查更新: AppState.addEventListener("change", (newState) => { newState === "active" && codePush.sync(); }); }componentWillMount() { // Ensure that any CodePush updates which are // synchronized in the background can't trigger // a restart while this component is mounted. // codePush.disallowRestart(); codePush.allowRestart(); }componentWillUnmount() { // Reallow restarts, and optionally trigger // a restart if one was currently pending. codePush.allowRestart(); }}MyApp = codePush(CodePushOptions)(MyApp);AppRegistry.registerComponent('codePushTest', () => MyApp);
0 0
- CodePush 热更新ReactNative之React Native Client SDK
- react-native热更新之codepush使用
- React-Native 热更新 CodePush
- CodePush 热更新React-Native(ios)
- react-native利用codepush实现热更新
- React Native用CodePush实现热更新
- ReactNative系列之十八codepush热更新
- CodePush 热更新ReactNative之CodePush CLI操作
- 使用codepush进行ReactNative热部署react-native-code-push
- React-Native热更新部署/热更新CodePush集成详解
- react native codepush热更新解决成功更新
- React Native应用部署/热更新-CodePush最新集成总结
- 使用CodePush热更新ReactNative JS代码
- React Native应用部署/热更新-CodePush最新集成总结(新)
- React Native应用部署/热更新-CodePush最新集成总结(新)
- React Native应用部署/热更新-CodePush最新集成总结(新)
- 利用CodePush对react-native项目热更新(以android为例)
- 零客户端开发经验 React Native 热更新 CodePush 打包集成指北
- git初始化之gitconfig
- MySQL查询不区分大小写
- UIView中的坐标转换
- ubuntu下安装tomcat并注册服务
- 关于Project Tango项目 你需要知道的一切
- CodePush 热更新ReactNative之React Native Client SDK
- libevent evhttp学习——http客户端
- Android System.exit(code) and android.os.Process.killProcess(pid)或者发生RunTimeException 导致应用重启
- Json对象和Json字符串的区别,以及Springmvc接受json字符串类型。
- strcmp 字符串比较
- 看看朝鲜是如何评价中国的真相令国人震惊
- ios UIWebView截获html并修改便签内容以及用js对图片进行缩放
- 过滤器和拦截器的比较及未登录用户权限限制的实现
- Java代码后台使用dip值设置width,heigth等