【问题标题】:react-native-admob Detect When Interstitial ad is Closedreact-native-admob 插页式广告关闭时检测
【发布时间】:2018-06-04 00:12:47
【问题描述】:

在我当前的应用程序中,我在我的应用程序中使用从 npm 安装的 react-native-admob 包,我可以让我的广告正常显示,但我现在需要在用户关闭广告时运行一个设置函数我我只使用插页式广告类型

我已经尝试设置事件监听器来运行一个函数,并使用下面的代码将监听器放置在 compenentwillmount 中

AdMobInterstitial.addEventListener('interstitialDidClose', () => {
  console.log('CLOSED');
  this.AdClosed('open');
});

但是一旦打开应用程序,AdClosed 功能就会运行,我如何仅在用户关闭插页式广告时才运行功能?

【问题讨论】:

    标签: react-native admob interstitial


    【解决方案1】:

    这就是我创建事件并将其添加到 react-native 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
    });
    

    希望对你有帮助。

    【讨论】:

      【解决方案2】:
      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();干活!!!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-05
        • 1970-01-01
        相关资源
        最近更新 更多