codepush热更新

codepush2之配置自己的服务器

codepush3之Android原生引用集成codepush

codepush4之linux下配置自己服务器


初始化阶段:

1:npm install -g code-push-cli 安装客户端

2:code-push -v 查看是否安装成功

3:code-push register 在codepush注册账号 

4:code-push login 

5:code-push app add <appName> <android/ios> react-native 添加app

例如code-push app add test android react-native 

6:code-push app list 列出app列表

code-push deployment  ls <appName> -k 查看APP的key

code-push deployment history <appName> Porduction/Staging

例如:code-push deployment history test Production

7:yarn add react-native-code-push 在rn项目下安装codepush

8:react-native link react-native-code-push 链接codepush

其他命令:

https://github.com/Microsoft/code-push/blob/master/cli/README-cn.md


配置阶段

Android:

1:项目settings.build

include ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')


2:App/build.gradle




3:MainApplication里面

@Nullable
@Override
protected String getJSBundleFile() {
  return CodePush.getJSBundleFile();
}

@Override
public boolean getUseDeveloperSupport() {
  return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
          new CodePush(“CODEPUSH_KEY”, MainApplication.this, BuildConfig.DEBUG)

  );
}


ios配置阶段:

yarn add react-native-code-push

react-native link react-native-code-push

然后找到info.plist文件 

CodePushDeploymentKey 填入codekey

ios目前不能再debug模式测试更新 因为会一直加载本地jsbundle 覆盖下载后的,所以看不到效果。

测试iOS

打开 AppDelegate.m文件

1:修改:

jsCodeLocation = [CodePush bundleURL];

//#ifdef DEBUG
  jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
//  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios"fallbackResource:nil];
//#else
//  jsCodeLocation = [CodePush bundleURL];
//#endif
//
2:打开 node_modules/react-native/scripts/react-native-code.sh 17-20

  # if [[ "$PLATFORM_NAME" = "iphonesimulator" ]]; then
      # echo "Skipping bundling for Simulator platform"
      # exit 0;
    # fi

3:重新react-native run-ios

然后再次热更新即可成功测试。
issue:https://github.com/Microsoft/react-native-code-push/issues/941


JS端:

import codePush from 'react-native-code-push'
componentDidMount(){
CodePush.sync({
    updateDialog: {
        mandatoryContinueButtonLabel:'更新',
        mandatoryUpdateMessage:'有新版本了,请您及时更新',
        optionalIgnoreButtonLabel: '稍后',
        optionalInstallButtonLabel: '后台更新',
        optionalUpdateMessage: '有新版本了,是否更新?',
        title: '更新提示'
    },
    installMode: CodePush.InstallMode.IMMEDIATE
});
}



使用阶段:

发布热更新命令

code-push release-react test android  --t 1.0.0 --dev false --d Production --des "更新描述” --m true

test注册codepushAPP的名字

android:平台 Android/ios

t :要对那个版本进行热更新这里是对1.0.0进行更新

dev:是否是开发者模式

dstaging/production 

des: 更新描述

m:是否强制升级

输入命令后会自动打包生产文件上传到codepush上面 


提示:

1:iOS和android最好将版本号改为x.x.x形式

2:使用staging时貌似成功几率很低

3:"react-native-code-push":"^4.1.0-beta",


截图:





tip

1:不适用于文件目录结构更改(添加文件可以)

2: 引入第三方后 如果修改了原生代码更新无法使用会导致闪退。

 

参考:

https://github.com/wuyunqiang/ReactNativeUtil/issues/26

http://blog.csdn.net/fengyuzhengfan/article/details/52003798

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


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值