Automatic deploy in ionic 2


#1

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


#2

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


#3

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?


#4

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


#5

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());
}


#6

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


#7

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());
}

#8

Posting code is not rocket surgery.


#9

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


#10

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


#11

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.


#12

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.


#13

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.


#14