Javascript 错误:firebase.admob()interstitalad.show()请求的interstitalad尚未加载,无法显示
我正在使用react-native firebase/admob在react-native中使用Adbmod,当我尝试在第一次单击时使用间隙广告时,它会打开广告,但从那时起它会返回以下错误:Javascript 错误:firebase.admob()interstitalad.show()请求的interstitalad尚未加载,无法显示,javascript,react-native,admob,react-native-firebase,firebase-admob,Javascript,React Native,Admob,React Native Firebase,Firebase Admob,我正在使用react-native firebase/admob在react-native中使用Adbmod,当我尝试在第一次单击时使用间隙广告时,它会打开广告,但从那时起它会返回以下错误: Error: firebase.admob () InterstitialAd.show () The requested InterstitialAd has not loaded and could not be shown. 代码与文档相同,可在此处找到: 基本上,你需要在浏览完广告后重新加载它。因
Error: firebase.admob () InterstitialAd.show () The requested InterstitialAd has not loaded and could not be shown.
代码与文档相同,可在此处找到:
基本上,你需要在浏览完广告后重新加载它。因此,您可以添加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();
};
}, []);