Updated October 9, 2019
CodePush Strategy for Beta Testing
CodePushManager.js
import React from 'react';
import { Platform } from 'react-native';
import codePush from 'react-native-code-push';
import AsyncStorage from '@react-native-community/async-storage';
const checkIfBetaTester = async () => {
const res = await AsyncStorage.getItem('MyApp::IS_BETA_TESTER');
return res === 'true';
};
const codepushKeys = {
staging: Platform.select({
ios: 'IOS_STAGING_KEY',
android: 'ANDROID_STAGING_KEY',
}),
production: Platform.select({
ios: 'IOS_PRODUCTION_KEY',
android: 'ANDROID_PRODUCTION_KEY',
}),
};
class CodePushManager extends React.Component {
componentDidMount() {
codePush
.notifyAppReady()
.then(() => checkIfBetaTester())
.then((isBetaTester) => {
if (isBetaTester) {
codePush.sync({
deploymentKey: codepushKeys.staging,
installMode: codePush.InstallMode.IMMEDIATE,
updateDialog: true,
});
} else {
codePush.sync({ deploymentKey: codepushKeys.production });
}
});
}
render() {
return null;
}
}
export default codePush({ checkFrequency: codePush.CheckFrequency.MANUAL })(
CodePushManager
);