Codes: automatic update


#1

is this correct?
any help guys?

app.component.ts

import { Component } from '@angular/core';
import { Platform, LoadingController, ToastController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

/* PLUGINS */

/* DEPLOY */
import {Deploy} from "@ionic/cloud-angular";

/* PUSH */
import { Push, PushToken } from '@ionic/cloud-angular';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:string = "Home";

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public push: Push, public loadingCtrl: LoadingController, public readonly toastCtrl: ToastController, public readonly deploy: Deploy) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });
    
    /* PUSH NOTIFICATIONS*/
    
    this.push.register().then((t: PushToken) => {
  return this.push.saveToken(t);
}).then((t: PushToken) => {
  console.log('Token saved:', t.token);
});
    
    this.push.rx.notification()
  .subscribe((msg) => {
    alert(msg.title + ': ' + msg.text);
  });
    
    /* END PUSH */
    
    /* DEPLOY */
    
   const checking = this.loadingCtrl.create({
     content: 'Checking for update...'
   });
   checking.present();

   this.deploy.check().then((snapshotAvailable: boolean) => {
     checking.dismiss();
     if (snapshotAvailable) {
       this.loadingCtrl.create();
     }
     else {
       const toast = this.toastCtrl.create({
         message: 'No update available',
         duration: 3000
       });
       toast.present();
     }
   });
 
   const updating = this.loadingCtrl.create({
     content: 'Updating application...'
   });
   updating.present();
   this.deploy.download().then(() => this.deploy.extract()).then(() => this.deploy.load());

    
    /* END DEPLOY */
    
  }

}

when in ionic serve it says:
Error: Missing deploy plugin: ionic-plugin-deploy

and when i try to run on my smartphone its stop working.
tnx in advance.


#2

Thank you for opening a new topic on this although you already had one! (I am being sarcastic here - this is very impolite).

No, as you said yourself it doesn’t work.

Your deploy code should be in platform.ready(), otherwise the plugin will not be available.
Your code itself also makes no sense: If there is no update available it starts downloading, extracting and loading anyway - of course this should be dependent on the result of check.


#3

im sorry for being impolite sir. :frowning:

when in ionic serve, i try to refresh the app its checking the update sir.but in smartphone its stop working.
if i will put it in platform.ready(), i dont have any idea how implement it cuz im new in ionic.
tnx in advance sir.


#4

What does that mean? If something stops, it has to work first. Does it work?


#5

this code in my smartphone no error.working normally my app
but its not checking or updating sir.

i try this:

platform.ready().then(() => {
        
        const checking = this.loadingCtrl.create({
     content: 'Checking for update...'
   });
   checking.present();

   this.deploy.check().then((snapshotAvailable: boolean) => {
     checking.dismiss();
     if (snapshotAvailable) {
       this.toastCtrl.create();
     }
     else {
       const toast = this.toastCtrl.create({
         message: 'No update available',
         duration: 3000
       });
       toast.present();
     }
   });
 
   const updating = this.loadingCtrl.create({
     content: 'Updating application...'
   });
   updating.present();
   this.deploy.download().then(() => this.deploy.extract()).then(() => this.deploy.load());
        
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

#6

Again, what does that mean? “working normally” is impossible, then you wouldn’t ask again and be happy that your code works.


Your code still has a logic errors:

  • It should only download, extract and load an update if it actually finds an update (snapshotAvailable). You have to move the other code inside the check if an update is available.
  • You probably also don’t want the “Checking for update” LoadingController every time you start the app, so remove that. Only open a Loadingcontroller if it actually finds an update.

Then you should add console.log() calls so you can understand “how far” the code actually gets and what is executed and what is not: Does is actually check if there is an update? (There is an update available, isn’t there?) Does it try to download it?

If you don’t get anything useful, maybe one of the calls is returning with an error? See how the methods of this.deploy handle errors.


#7

hello sir.i mean its working its checking for update but hes not updating.
i try this code but when i try in my emulator using bluestacks, i saw it updates but when i run in my smartphone the update is not working.only checking updates.

here is my code sir i insert in platform.ready();

platform.ready().then(() => {

        const checking = this.loadingCtrl.create({
     content: 'Checking for update...'
   });
   checking.present();
        
        this.deploy.check().then((snapshotAvailable: boolean) => {
            checking.dismiss();
  if (snapshotAvailable) {
    // When snapshotAvailable is true, you can apply the snapshot
	this.deploy.download().then(() => this.deploy.extract()).then(() => this.deploy.load());
  }
}); 

// Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

tnx in advance sir.


#8

So is a snapshot available?
Does it download?
Does it extract?
Does it load?
There is still no logging in your code that could tell you what is going on.

All these functions should also have error handling so you know if something goes wrong.