expo - InterstitialAd not loaded after the first trigger - Stack Overflow

admin2025-05-01  0

I get the ads when i click the button first time. When i trigger the ads next time its showing an error : InterstitialAd.show() The requested InterstitialAd has not loaded and could not be shown


const interstitial = InterstitialAd.createForAdRequest(adUnitId, {
  keywords: ['fashion', 'clothing'],
});

const Layout = () => {

  const [loaded, setLoaded] = useState(false);

  useEffect(() => {
    const unsubscribeLoaded = interstitial.addAdEventListener(AdEventType.LOADED, () => {
      setLoaded(true);
    });
    

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

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

  // No advert ready to show yet
  if (!loaded) {
    return null;
  }

  return (
    <>
      <Button
      title="Show Interstitial"
      onPress={() => {
        interstitial.show();
      }}
    />
    </>
  );
};````
转载请注明原文地址:http://anycun.com/QandA/1746112241a91838.html