invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
686 stars 139 forks source link

AppOpenAd.show(). The reaquested AppOpenAd has not loaded and could not be shown #206

Closed chungtvdev closed 2 years ago

chungtvdev commented 2 years ago

I am coding and some error " AppOpenAd.show(). The reaquested AppOpenAd has not loaded and could not be shown". Please help me

mikehardy commented 2 years ago

Hi there! You need to load the ad, then you may show it. Our example app has nice demonstrations of how to use the APIs

chungtvdev commented 2 years ago

import React from 'react'; import {View, Button } from 'react-native';

import { useState, useEffect } from 'react'; import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';

const adUnitId = 'ca-app-pub-3940256099942544~3347511713';

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

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

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

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

// Unsubscribe from events on unmount
return unsubscribe;

}, []);

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

return (