codepush2之配置自己的服务器

codepush热更新
codepush3之Android原生引用集成codepush
codepush4之linux下配置自己服务器

codepush会去访问微软的服务器,在国内网速特别慢基本上和不能用没有什么区别。今天我们就来配置自己的服务器。
好处
1:网络不受限制
2:自是服务器端变化了codepush的命令依旧可以使用功能上不受影响。

配置步骤

这里我们以本地服务器为例。

服务器端:

一:下载mysql https://dev.mysql.com/downloads/mysql/数据库
E8892167-0BFE-4593-88EB-F6C879925402.png
然后运行状态:
106080F6-5874-4FAA-8040-E4D403BB0B37.png

二:
git clone https://github.com/lisong/code-push-server.git
cd code-push-server
npm install
修改code-push-server/config/config.js配置文件
1:配置db

 db: {
    username: "root",
    password: "xxx",
    database: "codepush",
    host: "127.0.0.1",
    port: 3306,
    dialect: "mysql",
    logging: false
  },

2:配置local

  local: {
    // Binary files storage dir, Do not use tmpdir and it's public download dir.
    storageDir: "/Users/wuyunqiang/Documents/db/storage",//自定义
    // Binary files download host address which Code Push Server listen to. the files storage in storageDir.
    downloadUrl: "http://127.0.0.1:3000/download",//这里ip+端口改成本地的
    // public static download spacename.
    public:'/download'
  },

3:配置jwt

 jwt: {
    // Recommended: 63 random alpha-numeric characters
    // Generate using: https://www.grc.com/passwords.htm 随便写点什么 貌似没啥用 不过还是更具网站的随机生成一个吧
    tokenSecret:'xxxxxxxx....'
  },

4:配置common

  common: {
    // data dir for caclulate diff files. it's optimization. 配置数据存储位置。
    dataDir: "/Users/wuyunqiang/Documents/db/data",
    storageType: "local",
  },

三:初始化数据库
code-push-server-db init –dbhost localhost –dbuser root –dbpassword password//初始化数据库用户名和密码

四:启动数据库./bin/www 启动服务
binwwwsuccess.png

客户端

一:登录自己的服务器
因为我是本地服务器所以 code-push login http://127.0.0.1:3000/
logindb.png
登录窗口 用户名admin 密码:123456
获取token复制到终端。
36E4DA1F-897E-4336-9C8C-5D102A67AF1C.png
二:添加要热更新的APP
code-push app add appname android/ios react-native
三:将添加app获取的key配置到Android/iOS的代码中
setverkey.png
四:
Android配置src/java/名字/MainApplication

  new CodePush("xxxxxx",
                    getApplicationContext(), BuildConfig.DEBUG,"http://172.28.108.3:3000/")

服务器的ip,我配置的是本地网址 http://172.28.108运行在手机上的不能是127.0.0.1。
ios:配置info.plist

<key>CodePushDeploymentKey</key>
    <string>xxx</string>
    <key>CodePushServerURL</key>
    <string>http://172.28.108.3:3000/</string>

以上服务器和客户端配置完成。

使用

    InteractionManager.runAfterInteractions(() => {
            CodePush.sync({
                updateDialog: {
                    appendReleaseDescription:true,
                    descriptionPrefix:'更新内容:',
                    mandatoryContinueButtonLabel:'更新',
                    mandatoryUpdateMessage:'有新版本了,请您及时更新',
                    optionalInstallButtonLabel: '立即更新',
                    optionalIgnoreButtonLabel: '稍后',
                    optionalUpdateMessage:'有新版本了,是否更新?',
                    title: '提示'
                },
                installMode: CodePush.InstallMode.IMMEDIATE
            });
        })

改过后的应用上传:
code-push release-react <添加的APPName> android/ios –t 1.0.0(版本) –d Staging/Production –des “更新提示” -m false

上传文件成功后可以在/Users/wuyunqiang/Documents/db/data和/Users/wuyunqiang/Documents/db/storage看到文件
data.png

storage.png
运行截图:
ios.png

android.png

iosupdatesuccess.png

bug:
1:
codepushserverbug.png
这是数据库安装的问题。卸了再重新安装。

2:serverios.png
客户端地址错误。
iOS可能是info.plist的字段写错了,注意大小写.

3:android端可以收到更新提示框,但是点击下载更新就会报错如图。
codepushandroidrefused.png
原因:这个原因是因为config里面downloadUrl配置有问题,这里即便是自己本机作为服务器也不要127.0.0.1 换成电脑的ip即可。
ADF506B1FFFA0ECD3BFD1EAEF34B39EE.png
4:另外注意收集和电脑要在同一个网段先才能访问到你电脑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值