react native常见的错误

2024-06-19 12:38

本文主要是介绍react native常见的错误,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

http://blog.csdn.net/goodchangyong/article/details/51323930
http://blog.csdn.net/goodchangyong/article/details/51323930
http://blog.csdn.net/goodchangyong/article/details/51323930


react native常见的错误

  3116人阅读  评论(0)  收藏  举报
本文章已收录于: 
 React Native知识库
  分类:

更多组件https://React.parts/native,调用系统的,注意查看:支持iOS or 安卓

 

组件和相关使用

样式用这种方式定义,可以单独提出来成一个文件。

1.引入外部样式:

var Style = require('./Styles');

就可引入相对自己目录下的Styles.js,注:React Native 没有所谓的CSS

var styles = StyleSheet.create({ 

base: {

width: 38,

height: 38,

},

background: {

backgroundColor: '#222222',

},

active: {

borderWidth: 2,

borderColor: '#00ff00'

}

});

使用样式:

<Text style={styles.base} /> 

<View style={styles.background} />

 

2.以下是组件说明:

2.AppRegistry:应用注册,用于初始化启动应用

AppRegistry.registerComponent(项目名, () =><入口Class>);

例如:

AppRegistry.registerComponent('AwesomeProject', () => SampleComponent);

 

3.View:试图,里面可以套用子试图:

<View style={styles.view }>

      <View style={styles.subview }>

           你的其它组件

      <View>

</View>

布局使用的,Android 和 IOS 都支持。

 

4.Text:用于显示你要显示的文字:

<Text style={styles.Text }>你的文字</Text>

你可以配合字体样式去用

 

5.Image:用于显示图片信息:

<Image source={{uri: team.logo}} style={styles.thumbnail}/>

Source图片源(URL)(请求网络用uri,请求本地用:(require('image! <图片>')))

注意:图片只能放在:android\app\src\main\res\drawable-[尺寸],目录下,才能被找到,其它任意位置均不能使用本地图片(文件命名:全字母小写,才能使用,否则报错)。

 

 

6.ListView列表试图,用于渲染自定义列表:

<ListView 

dataSource={this.state.dataSource} 

renderRow={this.renderScoreboard}

style={styles.listView} />

dataSource:数据源(JSON 格式)

renderRow:自定义渲染行(绑定一个方法,在this下返回JSX,自定义行代码)

 

 

7.Loading加载试图的做法

  

1.this->renderLoadingView,建立一个显示 文字 或Image

 

2.在列表渲染的时候之前,做一个这个判断,让它显示。

这里说一下,请求数据,是如何工作的,这里要用到new ListView.DataSource 和fetch

 

3.如上图:初始化数据使用getInitialState,对dataSource初始化,

rowHasChanged: (row1, row2) => row1 !== row2,和下面这句

rowHasChanged: function(row1, row2){ row1 !== row2这两句是相等的,用于行是否改编

 

1. 请求数据使用的是fetch REQUEST_URL 是URL地址,第一个then用于 调试 或 改写返回结果,第二个then用于渲染界面,第三个catch是请求出错,所执行的。

2. 更多请求详情,可参考:https://github.com/github/fetch(文件上传 和 表单提交,添加头部 及 提交方式,可参考,最后两项)

 

8.TextInput文本输入框,用于输入文字的

<TextInput placeholder='Search via name or postcode' secureTextEntry={true} />

Placeholder:提示要显示的文字

secureTextEntry:是否是密码框

 

以下是三个触屏试图:

9.TouchableHighlight触屏高亮试图,体验效果更好。

<TouchableHighlight underlayColor='#99d9f4'>

<Text style={styles.buttonText}>Go</Text>

</TouchableHighlight>

underlayColor高亮所显示的颜色

 

10.TouchableNativeFeedback导航返回试图

<TouchableNativeFeedbackonPress={this._pressButton}                    background={TouchableNativeFeedback.SelectableBackground()}>

</TouchableNativeFeedback>

onPress绑定一个this->自定义方法,把自己Pop掉。

 

 

11.ToastAndroid安卓提示信息

ToastAndroid.show('This is a toast with long duration',ToastAndroid.LONG)}>

String:显示的信息

ToastAndroid.LONG:显示时间:长

ToastAndroid.SHORT:显示时间:短

 

注意:RN v18+ 以后的版本,会出现一个Bug,双击返回,关闭APPToastAndroid不会自动关闭问题(解决方案:请把源代码中的这个模块找到,拷贝到自己项目下app/src下,然后修改代码:ToastModule.Java,如网站中描述,修改文件ToastModule.javahttps://github.com/tdzl2003/react-native/commit/bbf66e4bcd045026728bd8f867d854da91d48565,请把代码中public void run(){ 前面加一个public,不然会编译报错,修改这个MainReactPackage.java 文件中的包位置package当前目录,然后把MainActivity.java 文中的包,指向MainReactPackage.java申明的包,问题就解决了}

 

其原因就是在主线程以外的地方运行Toast.show会产生这样的BUG,需将这段代码在UI线程执行(用偷梁换柱之计,解决此问题)

 

因为修改涉及到源代码,如果要在项目中修复,你可以自己复制一份MainReactPackage.java以及ToastModule.java,使用自己的ToastModule版本取代RN内置的版本,并进行对应的修改。我们已经测试过这种办法可以解决此问题。

 

12.SwitchAndroidAndroid交换开关

 

<SwitchAndroid onValueChange={(value) => this.setState({falseSwitchIsOn: value})} style={{marginBottom: 10}} value={this.state.falseSwitchIsOn} />

onValueChange:在值改变的时候,重置state.

Value初始化默认值

 

 

13.ProgressBarAndroidAndroid 加载动画

<ProgressBarAndroid styleAttr="Horizontal" />

 

styleAttr进度条的样式,包括以下六种

· Horizontal

· Small

· Large

· Inverse

· SmallInverse

· LargeInverse

 

页面之间参数传递,可以采用这种方式。

 

 

14. DrawerLayoutAndroidAndroid 右边浮动绘制层

<DrawerLayoutAndroid

drawerWidth={150}

drawerPosition={DrawerLayoutAndroid.positions.Left}

renderNavigationView={() =>navigationView}>

[内容部分]

</DrawerLayoutAndroid>

 

drawerWidth绘制的宽度

renderNavigationView绘制的视图,及左边布局的样子,元素

drawerPosition绘制的方式

· DrawerConsts.DrawerPosition.Left

· DrawerConsts.DrawerPosition.Right

15.navigator:场景切换函数

push导航到一个新的场景,挤压你当前任何场景

replace用一个新场景 替换 当前场景

pop回归上一个,并卸载当前场景

popToTop弹出堆栈中的第一个场景,卸载其他场景

popToRoute弹出一个特定的场景这之后所有的场景将被卸载

回传:但是navigator.pop() 并没有提供参数,因为pop() 只从 [路由1,路由2,路由3。。。]把最后一个路由踢出去的操作,并不支持传递参数给倒数第二个路由
所以:这里要用到一个概念,把上一个页面的实例 或者 回调方法,作为参数传递到当前页面来,在当前页面操作上一个页面的state 或 调用方法。

16. AsyncStorage:异步存储(键-值对存储,关闭APP后,仍然存储)

添加数据,代码如下:
AsyncStorage.setItem([key],[value]
.then(() => {debugger;}) 
.catch((error) => {debugger;}).done();

删除数据,代码如下:
AsyncStorage. removeItem([key]
.then(() => {debugger;}) 
.catch((error) => {debugger;}).done();

查询数据,代码如下:
AsyncStorage. getItem([key]
.then((value) => {debugger;}) 
.catch((error) => {debugger;}).done();

l then 返回的是正确(value: 查询的值),catch 返回错误(error.message:错误消息)

17. WebView:浏览器组件(Android0.17.0 以上,才支持,IOS:无限制

<WebView

                    ref={WEBVIEW_REF}

                    automaticallyAdjustContentInsets={false}

url={this.state.url}                    onNavigationStateChange={this.navigationStateChange}

                    startInLoadingState={true}

                />

RN: < v0.19 以前的

url加载的网页URL 地址。

html加载静态网页HTML

RN: >= v0.20 以上的

source提供以下,三种写法。

1. source={{uri: this.state.url}} URL地址

2. source={require('./helloworld.html')} 请求静态HTML文件

3. source={{html: HTML}} 加载静态网页HTML

注意他已经把url 和 html整合在一起了。

source扩展写法:

 

automaticallyAdjustContentInsets自动调整内容内边距

onNavigationStateChange导航状态发生改变时,如:(加载完成,加载中,加载错误)

startInLoadingState初始化加载状态,(true:一打开页面,就加载、false:默认不加载)

用这个组件,可以做APP浏览器,或者是OAuth 开源认证,登录的功能。

 

17. Animated:动画组件(Animated.ImageAnimated.TextAnimated.View

<Animated.Text

style={{

          fontSize: 26,

          fontWeight: 'bold',

          color: 'white',

          textAlign: 'center',

          transform: [                 // `transform` is an ordered array

            {scale: this.state.bounceValue}, // Map `bounceValue` to `scale`

          ],

          opacity: this.state.opacity

        }}

      >Douban Movie</Animated.Text>

React -> Animated (动画模块,在React)

Animated.spring:弹性动作(逐渐放大

Animated.decay: 弹性动作(逐渐放大 后 缩小

Animated.timing:平滑动作

duration:执行动画所花费的时间(ms

 

 

 

Flexbox 弹性盒子布局

 

 

 

flexDirection:  rowcolumn  (子元素排列方式)

 

flexWrap:wrap,nowrap  (单行,多行,容器会自动换行,布局到下一行,自适应布局)

 

alignItem:flex-start,flex-end,center,stretch (子元素,上下对齐方式)

 

justifyContent:flex-start,flex-end,center,space-between,space-around子元素,左中右对齐方式,类似Word文字排列方式

 

flex: 子元素,所占空间比列

 

alignSelf:auto,flex-start,flex-end,center,stretch  (单个元素对齐方式)

 

npm install(安装)、(npm uninstall卸载)如果不用了,建议卸载,否则会增加包大小

adb命令:

adb devices(查看adb管理的模拟器)

adb reboot(重启:模拟器)

adb remount(重新挂载系统分区)

以下是第三方控件(注意:第三方控件,也许会存在很多问题,甚至致命性的错误 和Bug,导致项目不能构造,有些问题需要自己解决,本文最后,提出了一些常见的错误解决方案):

splashscreen(欢迎荧屏)

n 安装1: npm install @remobile/react-native-splashscreen –save

n 注意:Installation (Android)下面的,是修改文件:[项目]\android\ settings.gradle 追加在后面。

n 添加自己的图片需要注意(添加后重新部署、添加必须是png,不能将jpg改成png,这种操作,否则会导致部署报错、注意尺寸

n 详细步骤:https://github.com/remobile/react-native-splashscreen

n 效果如图:

 

React Native Dialogs(系统对话框[RN:v 0.18,建议使用系统的,此插件有bug]

n 安装1npm install @remobile/react-native-dialogs –save

n 详细步骤:https://github.com/remobile/react-native-dialogs

n 步骤中,可能会遇到错误(3456

React Native ImagePicker(调用相册,选择图片)

n 安装1:npm install @remobile/react-native-image-picker –save

n 详细步骤:https://github.com/remobile/react-native-image-picker

n 步骤中,可能会遇到错误(789

选择后,如何显示选择的图片,请使用mapstate array,实现此功能,map,在0.17.0以后,遍历的元素,需要带上key,否则会有警告提示。

React Native Sqlite(使用本地数据库)

n 安装1:npm install @remobile/react-native-sqlite –save

n 详细步骤:https://github.com/remobile/react-native-sqlite

按照网上步骤走,这个插件,没有问题。

React Native FileTransfer(文件上传、下载)

n 安装1: npm install @remobile/react-native-file-transfer –save

n 详细步骤:https://github.com/remobile/react-native-file-transfer

React Native Camera(调用:摄像头,捕获图片 并 编辑)

n 安装1:npm install @remobile/react-native-camera –save

n 详细步骤:https://github.com/remobile/react-native-camera

使用Android GPS 功能)

n 配置xml:android\app\src\main\ AndroidManifest.xml,添加如下代码:

n <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 如图所示:

 

接下来用法:http://wiki.jikexueyuan.com/project/react-native/geolocation.html

使用谷歌地图组件(react-native-gmaps

n 先为模拟器安装1:Genymotion-ARM-Translation_v1.1.zip

n 命令:adb reboot,重启模拟器。

n 在安装2:gapps-kk-20140105-signed.zip

n 命令:adb reboot,重启模拟器,(下面建议)

VPN下面,注册谷歌账号,登录Google Play,成功后搜索一下(Google Drive)。

n 注册请在(VPN + chrome访问):chrome://chrome-signin/?source=8&constrained=0&frameUrlId=1&auto_close=1&showAccountManagement=1

n 启动后,会自动安装(Google Play Services

n 安装完成后,获取属于自己的api-key: https://developers.google.com/maps/documentation/android-api/signup?hl=zh-cn

n 更多实例:https://developers.google.com/maps/documentation/android-api/

其它安卓版本,安装(Google Play Services):

http://opengapps.org/  or 下面链接

https://www.androidfilehost.com/?w=files&flid=5648

n 执行安装:npm install react-native-gmaps --save

n 第三方库:https://github.com/teamrota/react-native-gmaps

n 常见错误(5

二维码显示插件(react-native-qrcode

n 安装1:npm install react-native-qrcode

n 详细步骤:https://github.com/cssivision/react-native-qrcode

DES 加密、解密(React Native Des

n 安装1:npm install @remobile/react-native-des –save

n 详细步骤: https://github.com/remobile/react-native-des

单选项(react-native-simple-radio-button

n 安装1:npm i react-native-simple-radio-button –save

n 详细步骤,样式局部,可能需要调整https://github.com/moschan/react-native-simple-radio-button

访问剪贴板(Clipboard

React -> Clipboard(原生框架自带)

n 网址信息:https://github.com/facebook/react-native/blob/90c7ad112f9e53dc6c71c8f47ea2a31b41d06141/Examples/UIExplorer/ClipboardExample.js

推荐:第三方 按钮组件(apsl-react-native-button

n 安装1:npm i apsl-react-native-button –save

n 提示:可实现,加载颜色变化Metor 风格  禁用(disable

n 更多资料:https://github.com/APSL/react-native-button

发送/派遣  指令给系统(react-native-send-intent

n 安装1:npm install react-native-send-intent –save

n 能做以下功能:1.信息分享、2.发送短信、3.发送电话(呼叫/不呼叫)、4.添加日历事件、5.打开日历事件

n 更多资料:https://github.com/lucasferreira/react-native-send-intent

扫描 条码、二维码(react-native-barcodescanner

n 安装1:npm i --save react-native-barcodescanner

n 配置权限:把下面,拷贝到文件AndroidManifest.xml 中:

n <uses-permission android:name="android.permission.CAMERA" />

n 页面引入组件,BarcodeScanner 必须是跟路径,最好另添一个页面。

n 详细步骤:https://github.com/ideacreation/react-native-barcodescanner

自定义徽章,可拖拽删除(未测试)(react-native-bga-badge-view

n 安装注意:没有托管到npm上,需手动下载项目,移植到node_modules

n 更多详情:https://github.com/bingoogolapple/react-native-bga-badge-view

 

使用第三方图表ichartjsreact-native-ichart

n 安装1:npm i react-native-ichart –save

n Android不能使用,需要修正(node_modules/react-native-ichart/ index.js)

n 需要使用RNv 0.18.0 以上的版本。

n 需要开启WebViewjavaScriptEnabledAndroid={true}domStorageEnabledAndroid={true} 和startInLoadingState={true}

n 需要从外部引入js 如下所示:

u <script type="text/JavaScript" src="…"></script>

u 库的位置:http://www.ichartjs.com/ichart.latest.min.js

n 更多资料:https://github.com/AdonRain/react-native-ichart

滑动块(react-native-slider

n 安装1:npm i --save react-native-slider

n 更多资料:https://github.com/jeanregisser/react-native-slider

系统的弹出菜单(react-native-simplemenu-android

n 安装1:因未托管npm,可以github上下载源码,拷贝node_modules,照资料里的文档配置,就可以使用了,资料如下:

n 更多资料:https://github.com/q-m/react-native-simplemenu-android

下拉选项框(react-native-dropdown-android

n 安装1:npm install --save react-native-dropdown-android

n 更多资料:https://github.com/chymtt/ReactNativeDropdownAndroid

进度条组件(react-native-progress

n 安装1:npm install react-native-progress --save

n 更多资料:https://github.com/oblador/react-native-progress

Image 图片加载进度(react-native-image-progress

,安装1:npm install react-native-progress --save

,安装2:npm install --save react-native-image-progress

n 更多资料:https://github.com/oblador/react-native-image-progress

Android状态栏,控件(react-native-android-statusbar

n 安装1:npm i --save react-native-android-statusbar

n 更多资料:

https://github.com/NishanthShankar/react-native-android-statusbar

分享链接组件(react-native-share

n 安装1:npm i --save react-native-share

n 更多资料:https://github.com/EstebanFuentealba/react-native-share

推送通知(本地 或 网络)(react-native-push-notification

n 安装1:npm i --save react-native-push-notification

n 更多资料:https://github.com/zo0r/react-native-push-notification

智能验证框架(tcomb-form-native

n 安装1:npm install tcomb-form-native --save

n 官方仅支持IOS(Android请使用RN v0.19,并覆盖:bootstrap 文件夹)

n 更多资料:https://github.com/gcanti/tcomb-form-native

图标集合组件(react-native-vector-icons

n 安装1:npm install react-native-vector-icons –save

n 注意:在RN v0.18 or later 版本,请使用它。

https://github.com/oblador/react-native-vector-icons#bundled-icon-sets(更多图片样式,竟在这些网页)

n 更多资料:https://github.com/oblador/react-native-vector-icons

滚动Tabs 面板(react-native-scrollable-tab-view

n 安装1:npm install react-native-scrollable-tab-view –save

https://github.com/brentvatne/react-native-scrollable-tab-view#props更多使用方式,请看此API

不带滑动翻页,请使用:react-native-tabs

n 更多资料:https://github.com/brentvatne/react-native-scrollable-tab-view

Flux 下的Router 组件(react-native-router-flux

n 安装1:npm install react-native-router-flux –save

n 如下代码: import {RouterRouteSchemaAnimationsTabBarActions} from 'react-native-router-flux';

n 注意:它搭配(react-native-tabs)使用,但自身代码上,存在问题,可用以下覆盖https://github.com/LynxITDigital/GeoEncoding 项目中的\node_modules\react-native-router-flux 去覆盖自己项目中的...

n 更多资料:https://github.com/aksonov/react-native-router-flux

打星星,评价组件(react-native-star-rating

n 安装RN 0.16以上:npm install react-native-button --save

n 安装()RN 0.16 以下:npm install react-native-star-rating --save

n 注意:支持半颗星,不支持滑动 打分RN:0.16 以上的,请安装react-native-button,然后用我项目中的Component\StarRating.js,去用。

n 更多资料:https://github.com/djchie/react-native-star-rating

Android 手机震动(react-native-vibration

n 安装1:npm i --save react-native-vibration

n 更多资料:https://github.com/ideacreation/react-native-vibration

热更新  技术(react-native-code-push

n 安装1:npm install --save react-native-code-push

n 注释:用于修复紧急补丁,重启app,替换有问题代码,而无须重新发布apk

更多信息,请看热更新,最后一章节,专门讲述(文档最下面)。

n 更多资料:http://microsoft.github.io/code-push/docs/react-native.html
https://github.com/Microsoft/react-native-code-push

获取缓存大小、清除缓存(react-native-http-cache

n 安装1:npm install react-native-http-cache --save

n 更多资料:https://github.com/reactnativecn/react-native-http-cache

邮件发送(react-native-mail

n 安装1:npm i --save react-native-mail

n 注意:它调用了系统的邮件发送机制,可用作反馈问题,等功能作用。

n 更多资料:https://github.com/chirag04/react-native-mail

视频播放器(react-native-video

n 安装1:npm install react-native-video –save

注意:它可播放 本地 或 流媒体,需自己设计播放控件,如:(暂停,播放,进度条,时间显示,全屏 等等功能)。

n 更多资料:https://github.com/brentvatne/react-native-video

日期选择器(react-native-datetime-picker

n 安装1npm install @remobile/react-native-datetime-picker --save

n 安装2npm install @remobile/react-native-simple-button --save

n 修改文件,如下图:node_modules\@remobile\react-native-datetime-picker\libs\ios

 

其它修改(Java 和 配置文件),必须删除APP后,重新部署使用方式,请看网站
https://github.com/cnjon/react-native-datetime-picker

单选框(可做:级联功能)

安装:npm install react-native-picker-android –save

导入一个公用组件之后,如果下图这样使用组件:

 

 

https://github.com/beefe/react-native-picker

图片轮播(react-native-swiper2)

安装:npm react-native-swiper2 –save

资料可查阅下面文档http://npm.taobao.org/package/react-native-swiper2

https://github.com/vczero/react-native-lesson/blob/master/%E7%AC%AC4%E7%AF%87React-Native%E5%B8%83%E5%B1%80%E5%AE%9E%E6%88%98%EF%BC%88%E4%BA%8C%EF%BC%89.md

https://github.com/leecade/react-native-swiper

打开外部浏览器(RN v0.19 以下的)

使用对象IntentAndroidReact --> IntentAndroid

React 下面的IntentAndroid 实例代码。

IntentAndroid.canOpenURL(url, (supported) => { 
if (!supported) { 
   console.log('Can\'t handle url: ' + url); 
} else { 
   IntentAndroid.openURL(url); 
} 
});

打开外部浏览器(RN v0.20 以上的)

IntentAndroid 已经标记为弃用(deprecated

请使用Linking对象React --> Linking

Linking 对象返回 Promise,代码如下:

或者是这样

常见错误

1.如果npm install,出现这个错误:

请安装:Microsoft Visual Studio Express 2013 for Windows Desktop,再次运行 ,可成功。

 

2.如果出现下面,这个错误:请安装Python27后,配置环境变量,方可成功。

3.如果安装遇到这个错误,缺少依赖包,注意它提出的版本号

 

请安装他提示的版本,再安装你要安装的,以下是:react-native run-android的错误

4.如果出现这个错误,不能找到npm 安装,依赖的项目。

 

请在自己项目下settings.gradle,配置依赖的项目,最好依赖的放到前面

 

5.如果出现这个错误,代表:实例化的类 和 导入的包不同。

 

 

6.如果出现这个错误,代表实例化构造方法,需要把this,传进去。

 

 

 

[错误代码如下图所示:

 

7.如果遇到下图这个错误,请修改(settings.gradle  -->路径:/android/,去掉后面的即可。

 

8.如果遇到下图这个错误,请导入包(import android.content.Intent):

 

9.如果遇到以下错误,请安装(npm i @remobile/react-native-cordova --save

 

IOS平台(外部安装包,环境搭建)

1.  XCode 中打开你的项目右击Libraries 选择Add Files to "项目名"

(用RCTVideo项目,而非图片中显示的截图)

2.添加 libRTCVideo.a  Build Phases -> Link Binary With Libraries

3. Build Phases -> Copy Bundle Resources中,添加视频文件 .mp4.

4. 现在,你就可以在项目中使用: var Video = require('react-native-video'); 

5. 更多描述 或 安卓的配置参看文档:https://github.com/brentvatne/react-native-video

Google Play Services

1.Google Map项目,APP用了Google Play Services,而机器没有安装:Google Play Services,在react-native run-android命令下,会报:type 3 错误。

 

 

初次使用会提示用户升级(Google Play Services),升级过程,需要用VPN下载,大约40多兆的文件大小。

 

Watchman versionv0.17建议改

默认是25000, 改大:MAX_WAIT_TIME(如:120000

文件位置:

\node_modules\react-native\packager\react-packager\src\FileWatcher\index.js

\node_modules\react-native\packager\react-packager\src\DependencyResolver\FileWatcher\index.js(新版本,在这儿(0.18.0),默认值,比较高)

官方网站:http://facebook.github.io/react-native/docs/troubleshooting.html

http://reactnative.cn/docs/Linux-windows-support.html#content

这个错误属于,模块是es6创建的,引入是es5require('./IChartDemo')

 

这个错误,如图代码,可以解决(ES6静态结构,必须要 号结束)。

 

另外(RNv0.18.0) 和 (RNv0.17.0)下面文件,会有区别

android\app\src\main\java\com\myproject\MainActivity.java

 

上图是:(RNv0.18.0,添加、导入 第三方包)

 

上图是:(RNv0.17.0,添加、导入 第三方包)

 

ES6 和 ES5,在(React-Native)项目中的对照表,请参考

http://bbs.reactnative.cn/topic/15/react-react-native-%E7%9A%84es5-es6%E5%86%99%E6%B3%95%E5%AF%B9%E7%85%A7%E8%A1%A8

 

 

 

热更新技术(Microsoft CodePush

 

 

1. 全局安装:npm install -g code-push-cli(命令才有:code-push

2. 查看code-push版本:code-push –v

 

3. 注册 code-pushcode-push register(它会打开网站,请登陆后,在注册code-push https://codepush.azurewebsites.NET/auth/register?hostname=USER-20150604HH,注册后,会生成 token,如下填写,就OK

 

4. 向code-push添加一个APPcode-push app add <MyApp>

 

5. 把生成的Key,填写到new CodePush([Key], this, BuildConfig.DEBUG); 代码中,代码在:MainActivity.java 文件中。

6. 查看code-push发布的列表:code-push deployment ls MyApp -k

 

7. 查询更新重启APP获取更新描述,请查阅资料:

建议放在:应用程序启动,在设置页面的点击按钮中,定期在某个固定的时间间隔,获取推送更新。

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

http://microsoft.github.io/code-push/docs/react-native.html

Code-Push发布APP更新

9. 发布APP更新

Ø 1.只发布JavaScript更新(JavaScript-only

l 1.打包成bundle JS压缩文件,react-native bundle --platform android --entry-file index.android.js --bundle-output codepush.js --dev true--dev:true 会提示所有 黄色警告,否则 不会

l 2. 使用code-push 发布:code-push release MyApp codepush.js 1.0.1

如:code-push release MyApp codepush.js 1.0.2 -d Production --des "Description,My is OK"

 

-d Production:指定发布分支,默认会发布到 [Staging分支下

--des: 发布描述,默认(空)字符串

 

版本号,必须带上,发布版本,只能 大于 服务器版本,否则(小于、等于)会报下面错误:

 

 

发布进度条,返回Successfully,代表当前发布成功,如图:

 

 

注意:分支,只会显示最后一个发布版本,如图

 

Ø 2.发布JavaScript + ImagesJS + 资源文件)

l 1.在项目目录下,创建一个文件夹(列如:release

l 2.执行react-native bundle --platform android --entry-file index.android.js --bundle-output ./release/main.jsbundle --assets-dest ./release --dev false

注意:输出文件,必须是(.js or .jsbundle)结尾,其它扩展名,将导致失败,这里多了一个,--assets-dest:资源输出目标文件夹

l 3.执行代码推送:code-push release MyApp ./release 1.0.0

注意:代码推送,将自动压缩(zipping)你的目标文件夹,并上传。

APIhttps://github.com/Microsoft/react-native-code-push#api-reference

注意:发布JavaScript + Images,必须是RNv0.19+code-push: v1.7.0  以上的版本。

0

这篇关于react native常见的错误的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1075058

相关文章

嵌入式软件常见的笔试题(c)

找工作的事情告一段落,现在把一些公司常见的笔试题型整理一下,本人主要是找嵌入式软件方面的工作,笔试的也主要是C语言、数据结构,大体上都比较基础,但是得早作准备,才会占得先机。   1:整型数求反 2:字符串求反,字符串加密,越界问题 3:字符串逆序,两端对调;字符串逆序,指针法 4:递归求n! 5:不用库函数,比较两个字符串的大小 6:求0-3000中含有9和2的全部数之和 7

C++工程编译链接错误汇总VisualStudio

目录 一些小的知识点 make工具 可以使用windows下的事件查看器崩溃的地方 dumpbin工具查看dll是32位还是64位的 _MSC_VER .cc 和.cpp 【VC++目录中的包含目录】 vs 【C/C++常规中的附加包含目录】——头文件所在目录如何怎么添加,添加了以后搜索头文件就会到这些个路径下搜索了 include<> 和 include"" WinMain 和

vue, 左右布局宽,可拖动改变

1:建立一个draggableMixin.js  混入的方式使用 2:代码如下draggableMixin.js  export default {data() {return {leftWidth: 330,isDragging: false,startX: 0,startWidth: 0,};},methods: {startDragging(e) {this.isDragging = tr

vue项目集成CanvasEditor实现Word在线编辑器

CanvasEditor实现Word在线编辑器 官网文档:https://hufe.club/canvas-editor-docs/guide/schema.html 源码地址:https://github.com/Hufe921/canvas-editor 前提声明: 由于CanvasEditor目前不支持vue、react 等框架开箱即用版,所以需要我们去Git下载源码,拿到其中两个主

React+TS前台项目实战(十七)-- 全局常用组件Dropdown封装

文章目录 前言Dropdown组件1. 功能分析2. 代码+详细注释3. 使用方式4. 效果展示 总结 前言 今天这篇主要讲全局Dropdown组件封装,可根据UI设计师要求自定义修改。 Dropdown组件 1. 功能分析 (1)通过position属性,可以控制下拉选项的位置 (2)通过传入width属性, 可以自定义下拉选项的宽度 (3)通过传入classN

js+css二级导航

效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Con

基于Springboot + vue 的抗疫物质管理系统的设计与实现

目录 📚 前言 📑摘要 📑系统流程 📚 系统架构设计 📚 数据库设计 📚 系统功能的具体实现    💬 系统登录注册 系统登录 登录界面   用户添加  💬 抗疫列表展示模块     区域信息管理 添加物资详情 抗疫物资列表展示 抗疫物资申请 抗疫物资审核 ✒️ 源码实现 💖 源码获取 😁 联系方式 📚 前言 📑博客主页:

vue+el国际化-东抄西鉴组合拳

vue-i18n 国际化参考 https://blog.csdn.net/zuorishu/article/details/81708585 说得比较详细。 另外做点补充,比如这里cn下的可以以项目模块加公共模块来细分。 import zhLocale from 'element-ui/lib/locale/lang/zh-CN' //引入element语言包const cn = {mess

vue同页面多路由懒加载-及可能存在问题的解决方式

先上图,再解释 图一是多路由页面,图二是路由文件。从图一可以看出每个router-view对应的name都不一样。从图二可以看出层路由对应的组件加载方式要跟图一中的name相对应,并且图二的路由层在跟图一对应的页面中要加上components层,多一个s结尾,里面的的方法名就是图一路由的name值,里面还可以照样用懒加载的方式。 页面上其他的路由在路由文件中也跟图二是一样的写法。 附送可能存在

vue+elementUI下拉框联动显示

<el-row><el-col :span="12"><el-form-item label="主账号:" prop="partyAccountId" :rules="[ { required: true, message: '主账号不能为空'}]"><el-select v-model="detailForm.partyAccountId" filterable placeholder="