Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using react-native-firebase / admob to use Adbmod in react native, and when I try to use Interstitial Ads on my first click it opens the ad, but from then on it returns this error:

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

The Code is the same as the documentation and can be found here:

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

like image 599
Paulo Henrick Avatar asked Mar 03 '23 06:03

Paulo Henrick


1 Answers

Basically you need to reload the ad after it has been viewed. So you could add an AdEventType.CLOSED listener and reload the ad there.

 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();
    };
  }, []);
like image 95
Varun Nath Avatar answered Mar 05 '23 15:03

Varun Nath