您的位置:首页 > Web前端 > React

react native code-push的使用

2016-03-31 00:00 519 查看
摘要: 成热打铁,最近在学习code-push,然而网上的教程少且不直观,所以就自己记录一下在项目中使用的过程

废话不多说,直接开始正文了!

参考文章:

很好的code-push中文教程

code-push的官方教程

官方的react-native-code-push插件的使用教程

1.安装code-push

npm install -g code-push-cli

2.注册code-push账号

code-push register

具体的步骤,请参考上文的第一篇文章

好的,现在可以注册一个App到code-push了

code-push app add CodePushDemo

如下图:



Staging是默认的部署名,记下它的Key值,下边会用到。

现在,需要修改react-native项目了。

1.添加react-native code-push插件

npm install react-native-code-push --save

2.android配置

a.编辑android/setting.gradle文件,如图:



b.编辑android/app/builde.gradle文件,添加依赖。(注意:这里还需要将defaultConfig->versionName改为1.0.0这种三个数字的格式)如图:



c.修改android入口文件,MainActivity.java,添加CodePush包,注意,这里这里的配置方法会根据react-native版本的不同而不同,

我的版本是0.22,具体的参考官方文档



d.修改javaScript代码

componentDidMount() {
CodePush.sync({
deploymentKey: "KGezOzb8AKHW1KSoRD46lvb7cH5SVycRHYbAe",
updateDialog: {
optionalIgnoreButtonLabel: '稍后',

3ff0
optionalInstallButtonLabel: '后台更新',
optionalUpdateMessage: 'Reading有新版本了,是否更新?',
title: '更新提示'
},
installMode: CodePush.InstallMode.ON_NEXT_RESTART
});
}

以上,code-push就算是配置万成了。下面就是如何更新app

第一步,package命令

cd CodePushReact

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

//完成后,会在项目根目录下生成release文件夹,但是后来我把这个删掉,直接运行下面的命令,一样可行,似乎可有可无,有大神可以在评论里告诉我吗?

code-push release-react
Usage: code-push release-react <appName> <platform> [options]

Options:
--bundleName, -b           Name of the generated JS bundle file. If unspecified, the standard bundle name will be used, depending on the specified platform: "main.jsbundle" (iOS) and "index.android.bundle" (Android)  [string] [default: null]
--deploymentName, -d       Deployment to release the update to  [string] [default: "Staging"]
--description, --des       Description of the changes made to the app with this release  [string] [default: null]
--development, --dev       Specifies whether to generate a dev or release build  [boolean] [default: false]
--disabled, -x             Specifies whether this release should be immediately downloadable  [boolean] [default: false]
--entryFile, -e            Path to the app's entry Javascript file. If omitted, "index.<platform>.js" and then "index.js" will be used (if they exist)  [string] [default: null]
--mandatory, -m            Specifies whether this release should be considered mandatory  [boolean] [default: false]
--rollout, -r              Percentage of users this release should be immediately available to  [string] [default: "100%"]
--sourcemapOutput, -s      Path to where the sourcemap for the resulting bundle should be written. If omitted, a sourcemap will not be generated.  [string] [default: null]
--targetBinaryVersion, -t  Semver expression that specifies the binary app version(s) this release is targetting (e.g. 1.1.0, ~1.2.3). If omitted, the release will target the exact version specified in the "Info.plist" (iOS) or "build.gradle" (Android) files.  [string] [default: null]

Examples:
release-react MyApp ios                    Releases the React Native iOS project in the current working directory to the "MyApp" app's "Staging" deployment
release-react MyApp android -d Production  Releases the React Native Android project in the current working directory to the "MyApp" app's "Production" deployment

code-push release-react CodePushReact android -t "1.0.0" --des "asd" -m true

到此结束!疑问一大堆啊!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: