Created
September 16, 2021 07:31
-
-
Save tolutronics/7a2b63ba2f8ae72d9f6efd543aba84c6 to your computer and use it in GitHub Desktop.
Receiving update from codepush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SyncStatus } from 'capacitor-codepush/dist/esm/syncStatus'; | |
import { codePush, InstallMode } from 'capacitor-codepush'; | |
import { Component } from '@angular/core'; | |
import { Platform } from '@ionic/angular'; | |
import { SplashScreen } from '@capacitor/splash-screen'; | |
import { App } from '@capacitor/app'; | |
@Component({ | |
selector: "app-root", | |
templateUrl: "app.component.html", | |
styleUrls: ["app.component.scss"], | |
}) | |
export class AppComponent { | |
constructor(private platform: Platform) { | |
this.initializeApp(); | |
this.checkUpdate(); | |
} | |
private initializeApp() { | |
this.platform.ready().then(async() => { | |
SplashScreen.hide(); | |
}) | |
} | |
checkUpdate(){ | |
App.addListener('appStateChange', ({ isActive }) => { | |
let deploymentKey; | |
if(this.platform.is('ios')){ | |
deploymentKey = 'YOUR_IOS_DEPLYMENT_KEY' // make sure you get this from your env | |
}else if(this.platform.is('android')){ | |
deploymentKey = 'YOUR_ANDROID_DEPLOYMENT_KEY' // make sure you get this from your env | |
} | |
if (isActive) { | |
codePush.sync({installMode: InstallMode.IMMEDIATE,deploymentKey:deploymentKey}) | |
.then( | |
(status) => { | |
switch (status) { | |
case SyncStatus.DOWNLOADING_PACKAGE: | |
//you can popup an alert here | |
break; | |
case SyncStatus.INSTALLING_UPDATE: | |
//you can popup an alert here | |
break; | |
case SyncStatus.ERROR: | |
console.log("----------------Error------------") | |
break; | |
} | |
},err=>{ | |
console.log(err) | |
} | |
); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment