在函数内等待AdMob免费奖励视频事件(Ionic/Typescript)

在函数内等待AdMob免费奖励视频事件(Ionic/Typescript),typescript,ionic3,Typescript,Ionic3,我有一个功能,检查用户是否看到或需要看到奖励视频,以便能够在我的ionic应用程序中使用该功能: let canUseThisFunction = await this.someService.canUseFunction(); if(canUseThisFunction){ console.log("can use"); } else { console.log("can NOT use"); } 检查功能类似于: canUseFunction(){ let c

我有一个功能,检查用户是否看到或需要看到奖励视频,以便能够在我的ionic应用程序中使用该功能:

let canUseThisFunction = await this.someService.canUseFunction();

if(canUseThisFunction){
     console.log("can use");
} else {
    console.log("can NOT use");
} 
检查功能类似于:

canUseFunction(){
    let canUse = await this.checkInBackend.checkIfUserHasReward();

    if(!canUse){
        await this.adService.showRewardVideo();   
     } else {
         return false;
     }
}
我遇到的问题是,在
checkIfUserHasReward()
调用
admob.rewardVideo.show()
之后,当奖励视频运行时,它只会解决“OK”问题

..
this.admob.rewardVideo.config(rewardVideoConfig);

        return this.admob.rewardVideo.prepare().then((prepareReward) => {
            console.log("prepareReward", prepareReward);
            return this.admob.rewardVideo.show();
        }).then(rewardShowed => {
            console.log("rewardShowed", rewardShowed);
            return rewardShowed;
        }).catch(e => console.error(e));
我可以使用

(document as any).addEventListener("admob.rewardvideo.events.REWARD")

但是它在我的
canUseFunction()之外解析。有没有办法在另一个函数中捕获此
eventListener

return new Promise(resolve => document.addEventListener("...", resolve);

您不应该强制转换到
any
。我不确定如何获取“官方”文档引用,而且没有
any
typescript,脚本说这是一个错误。这不是每次我返回承诺时都会创建一个事件侦听器吗?(即每次用户看到视频时)是的,是的。这不是你想要的吗?问题是用户可以(最终)看到多个视频。然后会有很多事件监听器(每个监听器都是在视频播放后创建的)。这不会造成内存泄漏吗?还是我理解错了?@distante:你是对的;您可以在承诺解析时删除事件处理程序。