在我目前的应用程序中,我使用在我的应用程序中从npm安装的react-native-admob软件包,我可以让我的广告显示正常,但我需要在用户现在关闭广告时运行设置功能我只使用插页式广告类型
我尝试设置事件列表器来运行一个函数,并使用下面的代码将侦听器放在compenentwillmount中
AdMobInterstitial.addEventListener('interstitialDidClose', () => {
console.log('CLOSED');
this.AdClosed('open');
});
但AdClosed功能在应用程序打开后立即运行如何仅在用户关闭非页内广告时才运行功能?
答案 0 :(得分:1)
这就是我如何创建和添加事件到反应原生的Interstitial admob广告:
AdMobInterstitial.setAdUnitID("ca-app-pub-3940256099942544/5224354917");
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
AdMobInterstitial.addEventListener("adClosed", () => {
//logic after ad have been closed
});
AdMobInterstitial.addEventListener("adFailedToLoad", () => {
//logic if ad have failed to load
});
希望它有所帮助。
答案 1 :(得分:0)
AdMobInterstitial.removeAllListeners(); //<- Add this line to close/remove event listener
AdMobInterstitial.setAdUnitID("ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX");
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
AdMobInterstitial.addEventListener("adClosed", () => {
//your stuff after ad is closed
});
AdMobInterstitial.addEventListener("adFailedToLoad", () => {
//stuff if ad have failed to load
});
AdMobInterstitial.removeAllListeners();做工作!!!