Open furkancelik opened 6 years ago
You're requesting the ad while it's already loaded. set adLoaded to the state from eventListener then request if it's not loaded!
I'm having the same problem.. I can't fix it
I am having the exact same problem only in Xcode simulator but on the device it works fine... can someone explain more the solution?
i have this problem too
Could someone solve this problem?
I had this exact issue as well, but did find that preloading the next interstitial on adClosed worked quite well. Here's an example of what I have in use now:
const [adLoaded, setLoaded] = useState(false)
const { myTrigger } = props
const requestAd = () => AdMobInterstitial.requestAd().catch(_error => setLoaded(false))
AdMobInterstitial.addEventListener('adLoaded', () => setLoaded(true))
// preload next ad after interstitial is consumed
AdMobInterstitial.addEventListener('adClosed', () => requestAd())
// show preloaded ad once the trigger is hit
useEffect(() => {
if (myTrigger) {
AdMobInterstitial.showAd().catch(error => console.log(`ShowAd: ${error}`))
}
// load on component mount and any state change, when needed
if (!adLoaded) {
requestAd()
}
return function cleanup() {
AdMobInterstitial.removeAllListeners()
}
})
return (
adLoaded ? <AfterAdComponent /> : <LoadingComponent />
)
This will preload the ad, and when the trigger is hit, show the ad. If the ad isn't ready when it's time to show (which causes the crash), it instead shows the LoadingComponent until the ad is loaded, and then shows the ad. You shouldn't see the LoadingComponent unless the ad is loaded too quickly, otherwise it will simply transition into the ad, and then render the AfterAdComponent without any crashes.
I hope someone else can make as much use of this, as I did. 👍
LAST EDIT: Updated to pattern so that it works with the edge case where re-triggering too fast causes it to show the ad before it's ready.
hi, I have nested components in AdMobInterstitial ads.
component1 (Game.js)
EndGame show Interstitial ads.
component2 (Header.js)
header, back page click show Interstitial ads.
error:
what could be the cause of the problem???