Closed chungtvdev closed 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
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 (
); } export default App;
Hi! Please give me the example
I am coding and some error " AppOpenAd.show(). The reaquested AppOpenAd has not loaded and could not be shown". Please help me