CodePush 集成详细步骤

1.RN集成

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


管理 CodePush 账号需要通过 NodeJS-based CLI

只需要在终端输入 npm install -g code-push-cli,就可以安装了。

安装完毕后,输入 code-push -v查看版本


2)在首页面

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


ComponentDidMount():

 i//CodePush

if (AppDef.debug) {


    CodePush.sync({

        updateDialog: {

            mandatoryContinueButtonLabel: '更新',

            mandatoryUpdateMessage: '有新版本了,请您及时更新',

            optionalIgnoreButtonLabel: '稍后',

            optionalInstallButtonLabel: '后台更新',

            optionalUpdateMessage: '有新版本了,是否更新?',

            title: '更新提示'

        },

        installMode: CodePush.InstallMode.IMMEDIATE

    });

} else {

    CodePush.sync();

}

CodePush.allowRestart();//在加载完了可以允许重启


componentWillUnmount():

    //code push

     CodePush.disallowRestart();//页面加载的禁止重启,在加载完了可以允许重启


2.iOS集成

1node_modules/react-native-code-push/ios/CodePush.xcodeproj 拖到工程里

添加依赖,添加libCodePush.alibz.tbd

2AppDelegate.m:

#import

jsCodeLocation = [CodePush bundleURL];

3plist里添加CodePushDeploymentKey

4Header Search Paths:

$(SRCROOT)/../node_modules/react-native-code-push recursive


3.android集成

1android/settings.gradle里添加:

include ':app', ':react-native-code-push'

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

2android/app/build.gradle里添加:

apply from: "../../node_modules/react-native/react.gradle"

apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"


compile project(':react-native-code-push')


DeploymentKey:

release {
    resValue "string", "CODEPUSH_KEY", "Product key"
}
debug {
    resValue "string", "CODEPUSH_KEY", "Staging key"
}

3MainApplication onCreate:

public void onCreate() {
    CodePush.setReactInstanceHolder((ReactInstanceHolder)mReactNativeHost);
    super.onCreate();


4MyReactNativeHost实现接口ReactInstanceHolder,并添加:

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


@Override
protected List getPackages() {
    return Arrays.asList(
            new MainReactPackage(),
            new FeePieViewPackage(),
            new BaiduMapViewPackage(),
            new CarRentPackage(),
            new StoragePackage(),
            new NetworkPackage(),
            new PayPackage(),
            new MyWebViewPackage(),
            new CodePush(getResources().getString(R.string.CODEPUSH_KEY), mContext, BuildConfig.DEBUG));
}






你可能感兴趣的:(iOS,android,reactNative)