Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Different versions available simultaneously #149

Closed
enricodeleo opened this issue May 3, 2016 · 3 comments
Closed

Different versions available simultaneously #149

enricodeleo opened this issue May 3, 2016 · 3 comments

Comments

@enricodeleo
Copy link

Hi!
Thank you for this great plugin! It's magical!

As far as I understood when I deploy a new bundle on S3 it is considered available to all the devices that have the same version in config.xml but with a lower ios-CFBundleVersion isn't it?
Is it possible to make different bundles coexist for different versions in order to update, when possible, different app versions?

@nikDemyankov
Copy link
Member

Hi,
thanks :)

As far as I understood when I deploy a new bundle on S3 it is considered available to all the devices that have the same version in config.xml but with a lower ios-CFBundleVersion isn't it?

Not exactly. You can restrict plugin from downloading web content by using min_native_interface preference in chcp.json. If it's higher, then the <native-interface version="" /> in your config.xml - plugin will not download the update from the server. More details about this can be found in documentation.

Is it possible to make different bundles coexist for different versions in order to update, when possible, different app versions?

Usually you would want your users to have the latest version of the app. It's a bit hard to maintain several versions of the web content at the same time. But this is doable via JS API.

Let's say you have several app versions: 1.x, 2.x and so on. And you want to provide updates for all of them. Assume, that your server's url is https://myserver.com/. Each app version should have it's own working folder with it's own chcp configs and web content. For example:

  • https://myserver.com/1.x/ for v1.x
  • https://myserver.com/2.x/ for v2.x.
  • and so on.

Basically, each new version will have an /[VERSION]/ folder on the server.

In that folder we place chcp.json, whose content is:

{
  "content_url": "https://myserver.com/[VERSION]/www/"
}

In https://myserver.com/[VERSION]/www/ we place web content, relative to the application's version. Also, there should be a chcp.manifest file.

We finished setting up server. Now lets configure our application.

First, in the config.xml disable auto installs and downloads:

<chcp>
  <auto-install enabled="false" />
  <auto-download enabled="false" />
</chcp>

You can omit config-file property in that case, because we will set it from JS side.

Now in your js/index.js do the following:

var app = {

  initialize: function() {
    this.bindEvents();
  },

  bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
  },

  onDeviceReady: function() {
   // [VERSION] should be replaced with the version of the app.
   // You can either get it from native, or hardcode, since you know which web content is for which app version
    var options = {
      'config-file': 'https://myserver/com/[VERSION]/chcp.json'
    };
    chcp.configure(options, app.didConfigureCHCP);
  },

  didConfigureCHCP: function(error) {
    if (error) {
      console.log('Failed to set chcp.json url');
      return;
    }

    chcp.fetchUpdate(app.didFetchUpdate);
  },

  didFetchUpdate: function(error, data) {
    if (error && error.code === chcp.error.NOTHING_TO_UPDATE) {
      console.log('Nothing new is available for download');
      return;
    }

    if (error) {
      console.log('Failed to download update');
      return;
    }

    chcp.installUpdate(app.didInstallUpdate);
  },

  didInstallUpdate: function(error) {
    if (error) {
      console.log('Failed to install update');
      return;
    }

    console.log('Update installed');
  }
};

app.initialize();

As you can see from JS code - first we set proper chcp.json url, and then fetching and installing update.

Right now you need to use chcp.configure() method, but I think in next versions I will deprecate it and instead you will pass chcp.json url directly in fetchUpdate method.

@enricodeleo
Copy link
Author

Clear and clever, I couldn't ask more. Thank you very much for your explanation!

@nordnet-deprecation-bot
Copy link
Contributor

👋 Hi! Thank you for your interest in this repo.

😢 We are not using nordnet/cordova-hot-code-push anymore, and we lack the manpower and the experience needed to maintain it. We are aware of the inconveniece that this may cause you. Feel free to use it as is, or create your own fork.

🔒 This will now be closed & locked.

ℹ️ Please see #371 for more information.

@nordnet nordnet locked and limited conversation to collaborators Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants