React-native-admob: The ad unit ID can only be set once on InterstitialAd

Created on 24 Jan 2017  Â·  11Comments  Â·  Source: sbugert/react-native-admob

Hey guys! It's anyway to check if unit ID is already setted up to avoid this exception?

Thanks!

bug

Most helpful comment

moving it before class declaration work for me thanks @fcpauldiaz

All 11 comments

I had the same problem, in my case I fixed the problem setting the IntersitialAd id just in index.android.js and index.ios.js

@mihaben how did you go about doing that? I tried and it just causes the app to crash.

I'm having the same error @mihaben from where did you removed it ?

Hey @fcpauldiaz and @marcusds , I was setting the InterstitialAd inside a component, so.. every time that the component was rendered, the InterstitialAd was setting again and that was provoking the problem, to fix the problem I moved the next 2 lines:

AdMobInterstitial.setAdUnitID('ca-app-pub-you-id');
AdMobInterstitial.setTestDeviceID('EMULATOR');

to index.android.js and index.ios.js, in this way you are just setting the ads when the app is started.

And inside the component, the code to show the ad:

AdMobInterstitial.requestAd(AdMobInterstitial.showAd);

set to global variable top of the index.js
var adIdSet = false;

and when you show itiyou need to check and your first time you wil need to set.

if (adIdSet != true) { AdMobInterstitial.setAdUnitID('ca-app-pub-2379123131358452/1851902925'); AdMobInterstitial.setTestDeviceID('EMULATOR'); AdMobInterstitial.requestAd(AdMobInterstitial.showAd); adIdSet = true; }else{ AdMobInterstitial.requestAd(AdMobInterstitial.showAd); }

Hmm I still having this problem when the user minimize (android back button) the application and reopen it later...

That must be because you open the interstitial on the onMount event, you have to move it before class declaration.

-------- Mensaje original --------
De: Federico Carrizo notifications@github.com
Fecha: 18/3/17 3:38 PM (GMT-06:00)
Para: sbugert/react-native-admob react-native-admob@noreply.github.com
Cc: Pablo Díaz Márquez pablo5_diaz@hotmail.com, Mention mention@noreply.github.com
Asunto: Re: [sbugert/react-native-admob] The ad unit ID can only be set once on InterstitialAd (#79)

Hmm I still having this problem when the user minimize (android back button) the application and reopen it later...

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/sbugert/react-native-admob/issues/79#issuecomment-287576746, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEUFFOu1bZcT5e6m5h99Ro8WbGfOlqZwks5rnE7KgaJpZM4Lsd0h.

I had the same problem on production.
Pull request #121 can fix this issue

moving it before class declaration work for me thanks @fcpauldiaz

We're bumping into the same issue.
It seems like everywhere else (like rewarded video, banner module, etc), before setting the ad unit id, there's a check whether the ID has been already set or not, except for InterstitialAd.
Is this intentional?

image

I think all of our problems would be solved if there was a check in RNAdMobInterstitialAdModule.java, too.

There's a PR with a fix: https://github.com/sbugert/react-native-admob/pull/204 waiting to be merged

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ozmaat picture ozmaat  Â·  3Comments

xvlm picture xvlm  Â·  5Comments

danvass picture danvass  Â·  6Comments

giladno picture giladno  Â·  6Comments

MohsinTariq10 picture MohsinTariq10  Â·  6Comments