首页 > 解决方案 > 错误:firebase.admob() InterstitialAd.show() 请求的 InterstitialAd 尚未加载,无法显示

问题描述

我正在使用 react-native-firebase / admob 在 react native 中使用 Adbmod,当我尝试在第一次点击时使用插页式广告时,它会打开广告,但从那时起它返回此错误:

Error: firebase.admob () InterstitialAd.show () The requested InterstitialAd has not loaded and could not be shown.

该代码与文档相同,可在此处找到:

https://rnfirebase.io/admob/displaying-ads#banner-ads

标签: javascriptreact-nativeadmobreact-native-firebasefirebase-admob

解决方案


基本上,您需要在查看广告后重新加载广告。因此,您可以添加一个 AdEventType.CLOSED 侦听器并在那里重新加载广告。

 useEffect(() => {
    const eventListener = interstitial.onAdEvent(type => {
      if (type === AdEventType.LOADED) {
        setLoaded(true);
      }
      if (type === AdEventType.CLOSED) {
        console.log("ad closed");
        setLoaded(false);
       
        //reload ad 
        interstitial.load();
      }
    });

    // Start loading the interstitial straight away
    interstitial.load();

    // Unsubscribe from events on unmount
    return () => {
      eventListener();
    };
  }, []);

推荐阅读