Automatic deploy in ionic 2

how to automatic deploy without using buttons.i want my app when they open it automatic it will check updates in deploy.

Are you talking about the Ionic Service/Cloud “Ionic Deploy”?

yes sir.but my app there is button so it can check updates.i want it to check automatic update when they open the app so its easy for the user.if this is possible sir?

Sure, just call the same method/function that your buttons triggers automatically on app start.

can you help me sir?if its ok?because i dont have any idea how to change the code sir.this is my code sir:

html:
(this is the button)
button (click)=“checkForUpdate()” ion-button icon-only block color=“royal”>
ion-icon name=“ios-sync”>
/button>

.ts:
(the function)
checkForUpdate() {
const checking = this.loadingCtrl.create({
content: ‘Checking for update…’
});
checking.present();

this.deploy.check().then((snapshotAvailable: boolean) => {
checking.dismiss();
if (snapshotAvailable) {
this.downloadAndInstall();
}
else {
const toast = this.toastCtrl.create({
message: ‘No update available’,
duration: 3000
});
toast.present();
}
});
}

private downloadAndInstall() {
const updating = this.loadingCtrl.create({
content: ‘Updating application…’
});
updating.present();
this.deploy.download().then(() => this.deploy.extract()).then(() => this.deploy.load());
}

Please format your code using the </> button above the input field. Select the code, then press it. Thanks.

like this sir?

html:
(this is the button)

<button (click)="checkForUpdate()" ion-button icon-only block color="royal">
<ion-icon name="ios-sync">
</button>

.ts:
(the function)

checkForUpdate() {
const checking = this.loadingCtrl.create({
content: 'Checking for update...'
});
checking.present();

this.deploy.check().then((snapshotAvailable: boolean) => {
checking.dismiss();
if (snapshotAvailable) {
this.downloadAndInstall();
}
else {
const toast = this.toastCtrl.create({
message: 'No update available',
duration: 3000
});
toast.present();
}
});
}

private downloadAndInstall() {
const updating = this.loadingCtrl.create({
content: 'Updating application...'
});
updating.present();
this.deploy.download().then(() => this.deploy.extract()).then(() => this.deploy.load());
}

Posting code is not rocket surgery.

There you have it: Just call this checkForUpdate() when the app starts.

1 Like

one last question sir.
where i will put the code sir?and how to call it sir?

Do you understand how code works? Call the method in your app.component.ts after platform.ready()

And stop writing “sir” all the time, this is really annoying.

1 Like

i understand any code but not all. cuz im new in ionic. im sorry sir. i just want to show respect here.heheh sorry for that.

is this correct sir?

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.