【问题标题】:Error: firebase.admob() InterstitialAd.show() The requested InterstitialAd has not loaded and could not be shown错误:firebase.admob() InterstitialAd.show() 请求的 InterstitialAd 尚未加载,无法显示
【发布时间】:2020-07-13 21:22:17
【问题描述】:
我正在使用 react-native-firebase / admob 在 react native 中使用 Adbmod,当我尝试在第一次点击时使用插页式广告时,它会打开广告,但从那时起它返回此错误:
Error: firebase.admob () InterstitialAd.show () The requested InterstitialAd has not loaded and could not be shown.
代码与文档相同,可以在这里找到:
https://rnfirebase.io/admob/displaying-ads#banner-ads
【问题讨论】:
标签:
javascript
react-native
admob
react-native-firebase
firebase-admob
【解决方案1】:
基本上,您需要在广告被查看后重新加载它。因此,您可以添加一个 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();
};
}, []);