Created
April 29, 2022 10:48
-
-
Save lennonjesus/eb70e80b790c2cd9244c8dbde2f8665e to your computer and use it in GitHub Desktop.
app-version.ts
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 { AppVersion } from '@ionic-native/app-version'; | |
import { Market } from "@ionic-native/market"; | |
import { Platform } from 'ionic-angular'; | |
// ... | |
class Blah { | |
rootPage: any; | |
pages: Array<{ title: string, icon: string, component: any }>; | |
mobileToken: string; | |
profile = {}; | |
photo = ""; | |
notificationData; | |
version = 'develop.00'; | |
isClt = false; | |
constructor( | |
public platform: Platform, | |
private storage: Storage, | |
private market: Market, | |
private appRemoteConfig: AppRemoteConfig /* Este é o meu código que vai ao backend saber qual é a versão mais recente do app */) { | |
// ... | |
} | |
async getVersionNumber() { | |
if (this.platform.is('cordova')) { | |
const versionNumber = await this.app.getVersionNumber(); | |
this.state.set('version', versionNumber); | |
this.version = this.state.get('version'); | |
this.appRemoteConfig.checkAppVersion(versionNumber).then(data => { | |
if (data.status === 'outdated') { | |
this.appRemoteConfig.getConfigurations().then(conf => { | |
const message = conf.messages.outdated_app; | |
let alert = this.alertCtrl.create({ | |
title: message.title, | |
message: message.body, | |
buttons: [ | |
{ | |
text: message.cta, | |
handler: () => { | |
this.market.open('br.com.melhoresdiaristas.app'); | |
this.nav.setRoot(LoginPage); | |
} | |
} | |
] | |
}); | |
alert.present(); | |
if (conf.version.mandatoryUpdate) { | |
this.nav.setRoot(LoginPage); | |
} | |
}); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment