What is code push:-
          CodePush is cloud service that enables React Native & Cordova developers to deploy mobile app update instantly to their users devices.
It Works by acting as central repository that developers can publish updates to (JS,HTML,CSS and images) file.

For example, we coded as “29 Jan 208 07:10 AM” instead of  “29 Jan 208 07:10 AM IST”. for this minor but important mistake, that type of changes we don’t need to create a build just using code push live changes update on existing build.

How to install react-native-code-push:
-> First create Appcenter account:- 
1.   AppCenter Login:-
 -First run this command appcenter login then open browser and browser provide one key those key paste in command prompt.
2.  AppCenter Logout:-
      –If you want to logout Appcenter then run below command
                                  appcenter logout
3.  You can login on appcenter using different account like,
                                –Github account
                                –Gmail account
                                –Facebook account 

Setup for Ios:-
1.  Login with any account and create app on appcenter click on Add new then open one Dialog write app name,select
os:Ios  and select Platform:React Native

                 –After create app select app                 
                 –Select Distribute->codepush->
                 Then run below commond:-
                  i) npm install -g appcenter
Then go to project path and run this command
2appcenter codepush release-react -a  UserName/AppName -d Production
                  – appcenter codepush release-react -a  swapnil-inheritx.com/pdfDemo -d Production
                  – appcenter codepush release-react -a  swapnil-inheritx.com/pdfDemo -d Staging
3. Now run below command
  -Go to project path and run below command:-
i) npm install –save react-native-code-push
            ii)  cd ios->pod install
4.Now go to appcenter then go to manage deployment and copy production key
              and paste in info.plist->CodePushDeploymentKey->Add Production key

5.Now go to App.js and write below code

import React, { Component } from ‘react’;
import Navigation from ‘./Navigation’;
import CodePush from ‘react-native-code-push’;
export default class App extends Component {
      componentDidMount= () => {
 CodePush.sync({ updateDialog:true, installMode:CodePush.InstallMode.IMMEDIATE })
.then(update => console.log(‘update’, update))
.catch(err => console.log(‘update error’, err));
     }
render() {
return (
<View>
</View>
);
}
}
6.Then create a build and install in your device

7.Now change in js file then open application you get a one dialog update available  then press install and you got changes in your application.

Setup for Android:-

  • 1.Same like ios create app on appcenter click on Add new then open one Dialog write app name,select os:Android  and select Platform:React Native

                 –After create app select app                 
                 –Select Distribute->codepush->
                 Then go to project path run this commond:- 
              i) appcenter codepush release-react -a  UserName/AppName -d Production
                  -appcenter codepush release-react -a   swapnil-inheritx.com/pdfDemo-1 -d Production
                  –appcenter codepush release-react -a   swapnil-inheritx.com/pdfDemo-1 -d Staging   
2.Now run below command
      — Go to project path and run below command:-
i) react-native link react-native-code-push
3.Now go to appcenter then go to manage deployment and copy production key
              and paste in android->app->src->main->res->values->string.xml
            Then paste below line
 <string moduleConfig=“true” name=“reactNativeCodePush_androidDeploymentKey”>Production key</string>
 <string moduleConfig=“true” name=“reactNativeCodePush_androidDeploymentKey”>G3M8MXtzCm7xEm3C8NYJ5npmt9AcfZGYnaholk</string>
4. Then create a build and install in your device
5. Now change in js code then open application you get a one dialog update available then press install and you got changes in your application.

 

You may also like

Leave a Reply