nordnet / cordova-hot-code-push

[DEPRECATED] - This plugin provides functionality to perform automatic updates of the web based content in your application.
https://github.com/nordnet/cordova-hot-code-push/issues/371
MIT License
979 stars 467 forks source link

Update work after restart the App #187

Closed davidellolio closed 8 years ago

davidellolio commented 8 years ago

Hi guys,

I have used javascript chcp support for the update the ionic project. The update works only restart the app.

Steps to reproduce

-auto-download set to true in config.xml -auto-install set to false in config.xml -Functions used :

checkForUpdate: function() { chcp.fetchUpdate(app.fetchUpdateCallback); },

fetchUpdateCallback: function(error, data) { if (error) { console.log('Failed to load the update with error code: ' + error.code); console.log(error.description); return; } console.log('Update is loaded, running the installation');

chcp.installUpdate(app.installationCallback);

},

installationCallback: function(error) { if (error) { console.log('Failed to install the update with error code: ' + error.code); console.log(error.description); } else { console.log('Update installed!'); } }

When the installation is terminated the installationCallback function is called and angular view my old homepage and not new homepage. If i want see the new homepage i must restart the app.

Could you help me?

Thank you, Davide

gareth-ferneyhough commented 8 years ago

Possible dup of #140. Are you deploying to a device via cordova? If so, what device type?

davidellolio commented 8 years ago

Hi @gareth-ferneyhough I use Ionic framework and have this problem in ios and android Device.

D.

nikDemyankov commented 8 years ago

@davidellolio can you share, what plugins are installed in your project?

Also, what version of Ionic platform?

davidellolio commented 8 years ago

Hi @nikDemyankov,

I used this plugins: "cordova-plugin-badge" "cordova-plugin-camera" "cordova-plugin-console" "cordova-plugin-contacts" "cordova-plugin-device" "cordova-plugin-device-orientation" "cordova-plugin-dialogs" "cordova-plugin-file" "cordova-plugin-file-transfer" "cordova-plugin-geolocation" "cordova-plugin-inappbrowser" "cordova-plugin-network-information" "cordova-plugin-screen-orientation": "cordova-plugin-splashscreen" "cordova-plugin-whitelist" "ionic-plugin-keyboard" "phonegap-plugin-push" "uk.co.workingedge.phonegap.plugin.launchnavigator" "cordova-plugin-x-socialsharing" "cordova-plugin-actionsheet" "cordova-hot-code-push-plugin" "cordova-hot-code-push-local-dev-addon" "de.appplant.cordova.plugin.local-notification" "cordova-plugin-x-toast" "dependent_plugins": { "cordova-plugin-app-event" "cordova-plugin-compat" }

ionic-version : 1.7.16

This is a log after installed:

07-18 10:17:50.284 12085-12214 D/CHCP: Dispatching Before install event
07-18 10:17:52.286 12085-16526 D/CHCP: Update is installed
07-18 10:17:52.299 12085-12085/ D/CHCP: Loading external page: /data/user/0/it.project/files/cordova-hot-code-push-plugin/2016.07.15-18.24.31/www/index.html
07-18 10:17:52.328 12085-12085/ D/JsMessageQueue: Set native->JS mode to null
07-18 10:17:52.412 12085-12214/ D/CordovaBridge: Ignoring exec() from previous page load.
07-18 10:17:52.454 12085-12085/ W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 12085
07-18 10:17:52.458 12085-12085/ W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 12085

Thank you

nikDemyankov commented 8 years ago

Hi,

Thanks! Will try to reproduce that.

davidellolio commented 8 years ago

I add more information:

Thank you, D.

nikDemyankov commented 8 years ago

In installationCallback I have put a $state.go("tabsController.home") to go in my homepage.

Actually, this line would be, probably, ignored. When update has been installed - plugin should reload webview to the index page. And the index page is the one, that is defined in config.xml:

<content src="index.html" />

So, it will take this url and load it in the view.

nikDemyankov commented 8 years ago

Haven't got time to play with your setup yet, sorry...

nikDemyankov commented 8 years ago

@davidellolio Tried it out for Android and worked fine. This is what I did:

  1. Created a tabbed Ionic project:

    ionic start Test tabs
    cd Test
    ionic platform add android
    ionic plugin add cordova-hot-code-push-plugin
    ionic plugin add <ALL_YOUR_OTHER_PLUGINS>

    The only plugin I skipped is cordova-hot-code-push-local-dev-addon, since you do the installation and download manually.

  2. Launched local server to ship files and generate configs:

    cordova-hcp server
  3. Configured config.xml:

    <chcp>
     <auto-download enabled="false" />
     <auto-install enabled="false" />
     <config-file url="https://18efd8cd.ngrok.io/chcp.json"/>
    </chcp>

    Again, I disabled both auto-install and auto-download, since you do it from JS code. As a config-url I set a local server's url.

  4. Added update code to www/js/app.js:

    angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
     .run(function($ionicPlatform) {
     $ionicPlatform.ready(function() {
       if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
         cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
         cordova.plugins.Keyboard.disableScroll(true);
       }
       if (window.StatusBar) {
         StatusBar.styleDefault();
       }
    
       // CHCP update code
       chcp.fetchUpdate(function(err, data) {
         if (err) {
           return;
         }
         console.log('Fetched update');
         chcp.installUpdate(function(err) {
           if (err) {
             console.log(err);
             return;
           }
           console.log('Installed');
         });
       });
     });
    })
    // the rest of the default project angular code
  5. Launched the app:

    ionic emulate android

    App started fine, but since I didn't change anything - no updates were downloaded.

  6. Updated text in www/templates/tab-dash.html and launched the app again. After a few moments update was downloaded and app reloaded to the index page, so I could see the changes.

System:

Can you try to do the same steps in your app and see, if it works? Maybe all you need is to remove cordova-hot-code-push-local-dev-addon from the project and set auto-install and auto-download to false? Also, check that there are no JS errors in the project, because this can lead to the issue you are having.

davidellolio commented 8 years ago

Thank you @nikDemyankov

I will check if have any issue in javascript and follow your steps.

davidellolio commented 8 years ago

@nikDemyankov I have deleted $state.go row in installationCallback function and now I don't have update problem. I have checked js files and I don't have error. Maybe this command is not accepted.

Thank you for your support.

nikDemyankov commented 8 years ago

Good :) Please, close the issue, if it is solved :)

davidellolio commented 8 years ago

Yes. Thank you