0
I have the code below, but the method showVideo()
is executed and follows the execution at the same time of the code below it, without waiting for the showVideo()
is due to simultaneous execution the value set in the Storage is not correct.
buscaBonus() {
this.servicoGeral.showVideo(); //esse metodo chama o `addTempo()` que por
sua vez chama um localStorage.setItem para setar o tempo ganho, e o código
abaixo recupera esse valor para mostrar em tela. Só deveria executar o
código abaixo após o `showVideo()`.
if (localStorage.getItem("segundos") == undefined) {
this.totalBonus = localStorage.getItem("segundos");
}
let alert = this.alertCtrl.create({
title: 'Você ganhou 5 segundos de bônus!',
message: 'Poderá utilizar e até acumular para jogar qualquer fase.',
buttons: [
{
text: 'Entendi ',
handler: () => {
return true;
}
}
],
enableBackdropDismiss: false
});
alert.present();
}
showvideo(): Promise<boolean>{
const rewardVideoConfig: AdMobFreeRewardVideoConfig = {
id: 'ca-app-pub-1390341047819209/6782590495',
isTesting: true,
autoShow: true
}
this.admobFree.rewardVideo.config(rewardVideoConfig);
return new Promise<boolean>((resolve) => {
rewardVideoClose = this.admobFree.on(this.admobFree.events.REWARD_VIDEO_CLOSE).subscribe(() => {
});
rewardVideoReward = this.admobFree.on(this.admobFree.events.REWARD_VIDEO_REWARD).subscribe(() => {
this.addTempo();
rewardVideoReward.unsubscribe();
});
this.admobFree.rewardVideo.prepare()
.then(() => { })
.catch(() => {
loading.dismiss();
resolve(false);
});
});
}
addTempo() {
if (localStorage.getItem("segundos") == null) {
this.tempoSegundos = 5
} else {
let tempo = localStorage.getItem("segundos");
this.tempoSegundos = (parseInt(tempo) + 5)
}
let tempo: string;
tempo = this.tempoSegundos.toString()
localStorage.setItem('segundos', tempo);
}
Should this function be observable? I am trying to use your code to do a test and error occurs in subscribe.
– i9on i9on
Trying to use without the same subscribe, was just an example.
– Péttrin Miranda
I think my problem is before then, because I have a method that calls this showVideo: searchBonus() hein this.servicoGeral.showVideo() //AT THIS TIME BEFORE THE ABOVE FUNCTION ALREADY EXECUTES THE BELOW CODE this.totalBonus = localStorage.getItem("seconds"); //AND CONSEQUENTLY STILL DOES NOT HAVE VALUE SAVED IN STORAGE }
– i9on i9on
I wanted to format the code above, but I couldn’t
– i9on i9on
Can you edit and put in the post? maybe you’ll get better understand
– Péttrin Miranda
done, I think I’ve changed up the problem now, I’ve remade the whole question.
– i9on i9on
this.admobFree.rewardVideo.prepare()
 .then(() => {this.addTempo })
 .catch(() => {
 loading.dismiss();
 resolve(false);
 });
– Péttrin Miranda
doesn’t work buddy
– i9on i9on
calling on prepare the video has not been watched yet and should not go through the
addTempo()
, the right would be at this eventREWARD_VIDEO_REWARD
, but I’ve made it with promisse and the functions are executed one after the other not waiting for the end of the first. I’ve tried several ways.– i9on i9on