一、在react-native项目中安装依赖,注意对应的版本要求

npm install react-native-code-push

版本

二、link

react-native link react-native-code-push
  1.Open your app's Xcode project
  2.Find the CodePush.xcodeproj file within the node_modules/react-native-code-push/ios 
  directory (or node_modules/react-native-code-push for <=1.7.3-beta installations) 
  and drag it into the Libraries node in Xcode

图片

  3.Select the project node in Xcode and select the "Build Phases" tab of your project configuration
  4.Drag libCodePush.a from Libraries/CodePush.xcodeproj/Products into the "Link Binary With Libraries" 
  section of your project's "Build Phases" configuration.

图片

  5.Click the plus sign underneath the "Link Binary With Libraries" list and select the libz.tbd 
  library underneath the iOS 9.1 node.

图片

三、将codepush 的staging 和release 配置到iOS项目中

3.1 在info.list 中添加key CodePushDeploymentKey 和string $(CODEPUSH_KEY)如下图所示

图片

3.2 在 project 中的 info 中添加 Staging ,选择release 版本如下图所示

图片

3.3 更改staging值

在setting 中 Build Location -> Per-configuration Build Products Path -> Staging 改变staging 的值从 $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 变成 $(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME) 图片

3.4 在setting只点击+ 号 选择 add 的这个

图片

3.5 找到 user-defined 中选择 配置如下

name 改成 CODEPUSH_KEY 在release 中和staging 中分别选择对应的key 这个key 就是 在 codepush 中的key, staging 对应 staging,production 对应的就是release。

  输入前面code-push add app 中注册应用得到的key

四、react-native 进行推送代码集成

4.1 引入依赖

  import CodePush from "react-native-code-push";

4.2 代码配置

4.2.1 首先最简单的一种就是 这种无声的热更新

也就是说热更新不会给用户任何提示,都在默默的进行更新,用户完全体会不到整个过程

  classMyAppextendsComponent<{}> {}

  MyApp= codePush(MyApp);

  export default MyApp;

4.2.1 有参数的更新

  classMyAppextendsComponent<{}> {}

  MyApp= codePush({ checkFrequency: codePush.CheckFrequency.ON_APP_RESUME, installMode: codePush.InstallMode.ON_NEXT_RESUME})(MyApp);

  export default MyApp;

   checkFrequency有三种状态如下

    ON_APP_START:  //在组件初始化的时候进行热更新
    ON_APP_RESUME://在每次app从后台回到前台的时候进行热更新
    MANUAL://不进行热更新,需要自己手动配置

   InstallMode 有如下几种状态

   IMMEDIATE  :// 安装热更新,并且重启app
   ON_NEXT_RESTART:  //下次启动的时候启动热更新
   ON_NEXT_RESUME  //从后台回到前台的时候启动
   ON_NEXT_SUSPEND:  在后台的时候进行热更新

4.3 在 componentDidMount中调用 sync方法

 codePush.sync()

五、xcode中修改ios代码

5.1 打开AppDelegate.m文件,引入头文件

 #import <CodePush/CodePush.h>

5.2

  NSURL *jsCodeLocation;


     #ifdef DEBUG
         jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
     #else
         jsCodeLocation = [CodePush bundleURL];
     #endif

六、进行发布

6.1 简化版发布更新

 code-push release-react <appname> ios -d Production #发布到code-push-server ios
 code-push release-react <appname> android -d Production #发布code-push-server android

6.2 复杂版发布更新

江苏卓易信息科技股份有限公司-TNG基础平台组 all right reserved,powered by Gitbook该文件最后修改时间: 2021-01-27 06:23:28

results matching ""

    No results matching ""