React Native热更新(iOS)-Pushy
React Native的出现,使的开发iOS代码出现了更便捷的方式。由于RN是使用脚本语言编写的,实现了“解释执行”的方式,而这种执行方式的修改只需替换脚步即可,不需要重新发布程序,热更新的方式极大的方便了迭代开发。
今天我们选择的热更新组件是Pushy,这是国内开发的,功能类似CodePush(CodePush在国内访问及其慢,长城宽度根本无法访问),Pushy支持增量更新,最大化的降低更新的数据量,节约流量。
下面介绍如何利用Pushy进行热更新:
1. 创建react native工程
$react-native init PushyDemo
2. 安装update工具, Pushy热更新需要update配合使用
- RN 0.29+
$npm install -g react-native-update-cli
- RN 0.28及以下
$npm install -g react-native-update-cli rnpm
3. 在PushyDemo目录下添加Pushy组件并自动link
- RN 0.29+
$ npm install --save react-native-update
$ react-native link react-native-update
- RN 0.27-0.28
$ npm install --save react-native-update@2.x
$ rnpm link react-native-update
- RN 0.26及以下
$ npm install --save --save-exact react-native-update@1.0.x
$ rnpm link react-native-update
4. 配置Bundle URL
- 在工程target的Build Phases --> Link Binary with Libraries中加入libz.tbd、libbz2.1.0.tbd
- 在你的AppDelegate.m文件中增加如下代码:
#import "RCTHotUpdate.h"
#if DEBUG
// 原来的jsCodeLocation
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
#else
jsCodeLocation=[RCTHotUpdate bundleURL];
#endif
5. 配置ATS
- 从iOS9开始,苹果要求以白名单的形式在Info.plist中列出外部的非https接口,以督促开发者部署https协议。在我们的服务部署https协议之前,请在Info.plist中添加如下,其中true的类型必须是String:
NSAppTransportSecurity
NSExceptionDomains
reactnative.cn
NSIncludesSubdomains
6. 登录与创建应用
- 登录
$ pushy
loginemail: <输入你的注册邮箱>
password: <输入你的密码>
- 创建应用
$ pushy createApp --platform ios
App Name: <输入应用名字>
7. 添加热更新
- 导入认证key,检查更新时必须提供你的appKey,这个值保存在update.json中
import {
Platform,
} from 'react-native';
import _updateConfig from './update.json';
const {appKey} = _updateConfig[Platform.OS];
- 检查更新,下载更新
checkUpdate = () => {
checkUpdate(appKey).then(info => {
if (info.expired) {
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
{text: '确定', onPress: ()=>{info.downloadUrl && Linking.openURL(info.downloadUrl)}},
]);
} else if (info.upToDate) {
Alert.alert('提示', '您的应用版本已是最新.');
} else {
Alert.alert('提示', '检查到新的版本'+info.name+',是否下载?\n'+ info.description, [
{text: '是', onPress: ()=>{this.doUpdate(info)}},
{text: '否',},
]);
}
}).catch(err => {
Alert.alert('提示', '更新失败.' + err);
});
};
8. 发布iOS应用
打包ipa文件,并把文件放到PushyDemo的根目录
上传ipa,以供后续版本对比只用
$ pushy uploadIpa PushyDemo.ipa
Uploading [==================================================================] 100% 0.0s
Ipa uploaded: 2362
GandalfdeiMac:PushyDemo gandalf$ pushy bundle --platform ios
Bundling with React Native version: 0.34.0
[2016-09-27 14:21:58] Building Dependency Graph
编译信息......(略)
[2016-09-27 14:22:25] Building Dependency Graph (26748ms)
transformed 368/368 (100%)
[2016-09-27 14:22:32] Finding dependencies (28763ms)
bundle: start
bundle: finish
bundle: Writing bundle output to: /Users/gandalf/Documents/kelvin/Github/HotUpdate/PushyDemo/build/intermedia/ios/index.bundlejs
bundle: Copying 5 asset files
bundle: Done writing bundle output
bundle: Done copying assets
Packing
Bundled saved to: build/output/ios.1474957297204.ppk
Would you like to publish it?(Y/N) Y
Uploading [==================================================================] 100% 0.0s
Enter version name: 1.1.0
Enter description: change upgrade description
Enter meta info: {"ok": 1}
Version published: 5244
Would you like to bind packages to this version?(Y/N) Y
2362) 1.0(normal) (newest)
Total 1 packages.
Enter packageId: 2362
OK.
- 随后你可以选择往AppStore发布这个版本,也可以先通过Test flight等方法进行测试,或者你可以把ipa包通过iTunes安装到手机进行后续测试。
9. 发布热更新版本
- 修改代码后,打包新的版本
$ pushy bundle --platform ios
Bundling with React Native version: 0.34.0
[2016-09-27 14:33:39] Building Dependency Graph
编译信息......(略)
[2016-09-27 14:33:51] Building Dependency Graph (12461ms)
transformed 369/369 (100%)
[2016-09-27 14:33:54] Finding dependencies (10696ms)
bundle: start
bundle: finish
bundle: Writing bundle output to: /Users/gandalf/Documents/kelvin/Github/HotUpdate/PushyDemo/build/intermedia/ios/index.bundlejs
bundle: Done writing bundle output
bundle: Copying 6 asset files
bundle: Done copying assets
Packing
Bundled saved to: build/output/ios.1474958010480.ppk
Would you like to publish it?(Y/N) Y
Uploading [==================================================================] 100% 0.0s
Enter version name: 1.2.0
Enter description: add image
Enter meta info: {"ok": 1}
Version published: 5247
Would you like to bind packages to this version?(Y/N) Y
2362) 1.0(normal) - 5244 Fv97KfnZ 1.1.0
Total 1 packages.
Enter packageId: 2362
Ok.
10. 点击客户端的刷新按钮,即可看到有更新版本的提示
到此,已经完成了植入代码热更新的全部工作。
参考资料如下
https://github.com/reactnativecn/react-native-pushy/
React Native热更新(iOS)-Pushy的更多相关文章
- react native 热更新
一.安装codepush服务 npm install code-push-cli -gcode-push -v 二.创建codepush账号 code-push registercode-push l ...
- React Native之code-push的热更新(ios android)
React Native之code-push的热更新(ios android) React Native支持大家用React Native技术开发APP,并打包生成一个APP.在动态更新方面React ...
- 如何用 React Native 创建一个iOS APP?(三)
前两部分,<如何用 React Native 创建一个iOS APP?>,<如何用 React Native 创建一个iOS APP (二)?>中,我们分别讲了用 React ...
- 如何用 React Native 创建一个iOS APP?(二)
我们书接上文<如何用 React Native 创建一个iOS APP?>,继续来讲如何用 React Native 创建一个iOS APP.接下来,我们会涉及到很多控件. 1 AppRe ...
- 如何用 React Native 创建一个iOS APP?
诚然,React Native 结合了 Web 应用和 Native 应用的优势,可以使用 JavaScript 来开发 iOS 和 Android 原生应用.在 JavaScript 中用 Reac ...
- React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)
React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...
- 封装 React Native 原生组件(iOS / Android)
封装 React Native 原生组件(iOS / Android) 在 React Native中,有很多种丰富的组件了,例如 ScrollView.FlatList.SectionList.Bu ...
- React native 之设置IOS的图标,名称和启动图(下篇文章会讲到RN的android的相关设置)
1.首先,app的名称: 如图所示:我的工程名叫BOOk 在BOOk下面的info.plist的文件里设置app的相关信息:比如Bundle name就是设置APP的名称 2.App的图标:(这里注意 ...
- React Native项目集成iOS原生模块
今天学习一下怎么在React Native项目中集成iOS原生模块,道理和在iOS原生项目中集成React Native模块类似.他们的界面跳转靠的都是iOS原生的UINavigationContro ...
随机推荐
- Django 踩过的坑(一)
平台:win10 工具:cmd python3 刚刚学习Django搭建环境,网站还木有发布,就直接来了个大麻烦. 一切按着<Django 学习笔记(二)>这篇文章来的,在最后cmd运行服 ...
- PHP源码阅读strtr
strtr 转换字符串中特定的字符,但是这个函数使用的方式多种. echo strtr('hello world', 'hw', 'ab'); // 第一种 aello borld echo strt ...
- Struts 之 通配符 路径匹配 常量用法 配置默认值
Struts 框架学习 Action的开发的几种方式 方式1 : 继承ActionSupport 如果使用Struts校验功能,必须继承此类 方式2 : 实现Action接口 方式3 :不继承 ...
- Iterator对对象遍历
//实例对象tables List<Table> tables = new TableManager(getApplicationContext()).queryTables(); sp ...
- HDU 1728 逃离迷宫(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题目: 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) ...
- 输入三个整数x、y、z,请把这三个数由小到大输出
题目:输入三个整数x,y,z,请把这三个数由小到大输出. 程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x> y则将x与y的值进行交换,然后再用x与z进行比较,如果x> ...
- Webi Report 展示 图片链接 (Image Link)
最近由于项目需求,在生成的Webi Report中需要增加一列展示相关数据系统的图片链接,要求用户可以通过点击图片链接展示图片. 方法如下: 1,首先找到系统中图片,查看随机一张图片的属性,找到图片的 ...
- jmeter之BeanShell对两个变量断言对比
在jmeter的中,断言没法对两个变量的进行对比后判断,只能使用Bean Shell断言来进行. 假设需求: 获取某类型用户uid个数与数据库查询结果是否相等 获取uid个数用http接口获取统计数据 ...
- SQL注入的各种类型的检测方式
#SQL注入各个类型检测方式 http://127.0.0.1/day6/1.php?id=1 union select 1,name,pass from admin 数字型 数字型不用特意加字符,直 ...
- 一个爬取Bing每日壁纸的python脚本
1. 背景 Bing搜索每天的背景图片有些比较适合做桌面,但是有的提供下载有的不提供下载.每天去点击下载又不太方便,所以第一次学习了一下python爬虫怎么写,写的很简单. 2. 相关技术 2.1 P ...