Ionic Deploy

Embed Size (px)

Citation preview

  • 8/18/2019 Ionic Deploy

    1/8

    Setup

    In the terminal in your project folder type

    ionic add ionic-service-deploy

    This downloads the required javascript libraries, injects the script tags into the

    index.html and adds ionic.service.deploy as a dependancy to the app modules list in

    app.js

    DOUBLE CHECK this last part actually happened!

    then type

    ionic plugin add ionic-plugin-deploy

    This installs the cordova plugin that actually performs the check agains the ionic

    servers for the latest code, downloads onto the device, unzips, installs and restarts thedevice.

    Ionic Service Deploy

    Page 1codecrapro.com | Ionic Service Deploy

  • 8/18/2019 Ionic Deploy

    2/8

    Implement Deploy Code

    In your app.js add the following code

    app.run(function ($ionicPlatform, $ionicDeploy) {

    $ionicPlatform.ready(function () {

    $ionicDeploy.watch().then(

    function noop () {

    },

    function noop () {

    },

    function hasUpdate (hasUpdate) {

    console.log("Has Update ", hasUpdate);

    if (hasUpdate) {

    console.log("Calling ionicDeploy.update()");

    $ionicDeploy.update().then(function(res) {

    console.log('Ionic Deploy: Update Success! ', res);

    }, function(err) {

    console.log('Ionic Deploy: Update error! ', err);

    }, function(prog) {

    console.log('Ionic Deploy: Progress... ', prog);

    });

    }

    });

    });

    });

    This checks the ionic servers every 60s for an update, if it nds one it then updates and

    restarts the application automatically.

    • The app.run function is run aer the applicaiton has initialised.

    • The $ionicPlatform.ready function only runs when the ionic application has

    completed loading on the device.

    • The $ionicDeploy.watch() function starts checking every 60s to see is there is an

    update on the ionic servers for a new version of your application.

    • The third param to the then() function callback (the notify function on a

    promise) is called every 60s, it's passsed in a true if it's found an update and false

    if it hasn't found an update.

    Ionic Service Deploy

    Page 2codecrapro.com | Ionic Service Deploy

  • 8/18/2019 Ionic Deploy

    3/8

    • If hasUpdate is true it then called the $ionicDeploy.update(), this performs the

    actual job of downloading the update from the ionic servers, unzipping,

    installing and then restarting the application.

    Ionic Service Deploy

    Page 3codecrapro.com | Ionic Service Deploy

  • 8/18/2019 Ionic Deploy

    4/8

    Create your rst upload

     We now want to create our rst upload to the ionic servers.

    In the terminal in your project folder type

    ionic upload --note="initial"

     Aer that nishes check apps.ionic.io

    1. Click the app you've just created.

    2. Check the Deploy folder.

    3. You should be able to see the upload you just created called initial.

    Ionic Service Deploy

    Page 4codecrapro.com | Ionic Service Deploy

  • 8/18/2019 Ionic Deploy

    5/8

    Deploy an application upload

     We've uploaded a version of our application, but we haven't "deployed" it yet, i.e. we

    haven't told ionic.io that this is the current latest version of our application.

    1. Press Deploy

    2. Press Deploy

    Ionic Service Deploy

    Page 5codecrapro.com | Ionic Service Deploy

  • 8/18/2019 Ionic Deploy

    6/8

    Deploy versioning 

    If you now started up the application in the simulator or in xcode and looked at the

    logs, you would notice that the application when starting up, performs a deploy. i.e. the

    application at this point downloads the deploy tagged as "initial", then uzips and

    updates the application.

    • This might seem strange since the "initial" version on app.ionic.io is actually the

    exact same code as is being run in the simulator.

    • So ionic deploy did a completely uncessary update of our application.

    The reason for that is that we need to tell ionic which version each deploy is assocaited

    with, so it checks to see if the deploy version is greater than the current application

    version and only then will it try to install the deploy version.

    First o nd the current version of your application, you can nd in this in your

    cong.xml in the project root.

    Ionic Service Deploy

    Page 6codecrapro.com | Ionic Service Deploy

  • 8/18/2019 Ionic Deploy

    7/8

    Set the version of an upload

    1. Find the deploy you've just uploaded, either press edit or if it's already activated

    press active.

    2. Then in the equivalent eld put the current version number of the application,

    so in our case i would put verson 0.0.1 in the equivalent elds.

    This then tells ionic that for the deploy called "initial" it matches version 0.0.1 of the

    application.

    Now when you run the app in the emulator it won't try to download the initial version

    and install, since it knows that the initial version is 0.0.1 and the current app verson is

    0.0.1 so there is no need to update.

    Ionic Service Deploy

    Page 7 codecrapro.com | Ionic Service Deploy

  • 8/18/2019 Ionic Deploy

    8/8

    Ionic Service Deploy

    Page 8codecrapro.com | Ionic Service Deploy