美文网首页
ReactNative 之 code-push-server

ReactNative 之 code-push-server

作者: IMSong | 来源:发表于2018-06-20 14:55 被阅读17次
    前言.png

    前言:code-push是 software 开源的一套可用于React Native,Cordova等的热更新功能,可以省去原生开发的审核机制,节约开发的时间成本,国内也有Pushy.但是 code-push 是在微软的服务器不方便调试,而且很不稳定,说不定还要收费,code-push-server可以解决此痛点.

    1,安装code-push-server (源码安装,当然还可以使用 npm 方式的安装)

    git clone https://github.com/lisong/code-push-server.git
    cd code-push-server
    npm install

    2,初始化数据库(记得安装 MySQL 数据库)

    ./bin/db init --dbhost localhost --dbuser root --dbpassword 123456(改为你自己的数据库密码)

    3,启动server

    ./bin/www

    会发现一堆的错误,是因为我们需要修改 config.js(位于code-push-server/config)


    修改红框中的其他默认 创建路径
    创建路径

    4,终端登录 server

    code-push login http://127.0.0.1:3000

    输入命令 登录系统获取 token
    点击获取
    填写 token,登录成功

    5,创建新的项目,注意版本iOS or Android

    code-push app add 项目名称-ios ios react-native

    创建新的项目

    6,查看项目的 key

    code-push deployment ls marketRN-ios -k

    查看项目的 key

    6,查看项目的上传记录

    code-push deployment h marketRN-ios Staging


    查看项目的上传记录

    7,上传热更新内容

    code-push release-react marketRN-ios ios

    上传热更新内容

    8,配置 APP, 以 iOS 为例

    用 Xcode,打开 iOS 版本的应用,修改 info.plist, 添加两个字段


    添加字段

    <key>CodePushDeploymentKey</key>
    <string>MEXuvXUBggE4HcLDnVgW9UP2f6TJ4ksvOXqog</string>
    <key>CodePushServerURL</key>
    <string>http://127.0.0.1:3000</string>

    9,添加RN 代码

    关键代码
    onCheckUpdate() {
            codePush.checkForUpdate()
            .then((update)=>{
                if (!update) {
                    alert('已是最新版本,客官请等等~');
                }else{
                    codePush.sync({
                        // updateDialog: true,
                        updateDialog: {
                            optionalIgnoreButtonLabel: '稍后',
                            optionalInstallButtonLabel: '立即更新',
                            optionalUpdateMessage: '发现新版本,是否更新?',
                            title: '提示'
                        },
                        installMode: codePush.InstallMode.IMMEDIATE,
                        //宋金委本地的 codepushserver 的 key
                        deploymentKey: 'MEXuvXUBggE4HcLDnVgW9UP2f6TJ4ksvOXqog'
                    });
                }
    
            });
    }
    

    10,测试示意图

    提示更新
    已是最新

    相关文章

      网友评论

          本文标题:ReactNative 之 code-push-server

          本文链接:https://www.haomeiwen.com/subject/fnaaeftx.html