Ionic Pro Live Deploy: How do I easily switch channels between Master and Production?

From the setup guide: https://ionicframework.com/docs/pro/deploy/setup/

I have to specify the Channel Name when installing the plugin:

cordova plugin add cordova-plugin-ionic --save --variable APP_ID="YOUR_APP_ID" --variable CHANNEL_NAME="YOUR_CHANNEL_NAME" --variable UPDATE_METHOD="background"

I guess that means for development I’ll need to install this plugin and specify “Master” as the channel name. Once I want to publish the app to the app store, I’ll need to remove this plugin and install it with “Production” as the channel name.

Is there any easier way to switch between these two channels, without uninstalling and reinstalling the plugin?

Side question: does Live Deploy update native resources? For example, app icons, splash screens, android’s res folder, etc.

Thanks!

7 Likes

I’m wondering the same thing

I’m interested in this solution, too. Any news on that?

Hi, I have the same question, did you figure out a more convenient solution ?

This should work:

Anyone using IonicCordova with Ionic v1(no typescript) can implement the same with something like this:

window.IonicCordova.deploy.init(config, function(initResponse){
    console.log(initResponse);
    if(initResponse === "OK"){
      window.IonicCordova.deploy.check(function(checkResponse){
        console.log(checkResponse);
        if(checkResponse === 'true'){
          window.IonicCordova.deploy.download(function(dlResponse){
            console.log(">>> Download progress: " + dlResponse);
            if(dlResponse === 'true' || dlResponse == 'false'){
              window.IonicCordova.deploy.extract(config.appId, function(extractResponse){
                console.log(extractResponse);
                if(extractResponse === 'true' || extractResponse == 'false'){
                  window.IonicCordova.deploy.redirect();
                }else{
                  // It's a progress update
                  console.log('>>> Extract progress:', extractResponse);
                }
              });
            }
          });
        }else{
          // It's a progress update
          console.log('>>> Ionic update not needed');
        }
      });
    }else{
      console.log('>>> Ionic Deploy unable to init');
    }
  });

I am currently testing Ionic pro at the moment and from what I can tell you can switch channels by modifying the UPDATE_METHOD in your config.xml

<plugin name="cordova-plugin-ionic" spec="~2.0.3">
        <variable name="APP_ID" value="xxxxxxx" />
        <variable name="CHANNEL_NAME" value="Master" />
        <variable name="UPDATE_METHOD" value="background" />
        <variable name="UPDATE_API" value="https://api.ionicjs.com" />
        <variable name="MAX_STORE" value="2" />
    </plugin>

Hi guys, and anybody that lands here after a Google search.

After some research I think I figured out a good way to do it : using git branches.

As you may know, the default git branch is “master”. When you do git push ionic master you effectively send master to Ionic Pro.

You could create a second branch, let’s call it “production”, which contains all the modifications needed for a production app, be it your API endpoint or in this case the Deploy configuration.

I strongly encourage you to read about git branching but if you’re lazy here is the tl;dr:

git checkout -b production
cordova plugin add cordova-plugin-ionic --save \
--variable APP_ID="XXXXXXXX" \
--variable CHANNEL_NAME="Production" \
--variable UPDATE_METHOD="background"
git add -p
git commit -m "Create production branch with Deploy production channel"
git push ionic production
git checkout master
# Continue working on master as normal
# When you are ready for production you can switch back and merge all your changes to production :
git checkout production
git merge --no-ff master
# note : rebase is probably safer, in particular if you committed changes to the lines that need to be different in prod
git push ionic production
git checkout master
# Repeat

Hope it helps!

2 Likes

How come I never thought about this! Good solution!

Definitely, using version control is the best option. But it is not necessary to reinstall the plugin in each branch. Just make the parameter changes in the files “package.json” and “config.xml”

This might help: https://ionicframework.com/docs/pro/deploy/tutorials/#setting-up-a-beta-channel