react-native-admob icon indicating copy to clipboard operation
react-native-admob copied to clipboard

AdMobInterstitial undefined is not a function

Open aligenc opened this issue 8 years ago • 3 comments

import { AdMobInterstitial } from 'react-native-admob';
...
componentDidMount() {
      AdMobInterstitial.setTestDeviceID('EMULATOR').catch(error => console.warn(error));
      AdMobInterstitial.setAdUnitID(admobInterstitialUnitId).catch(error => console.warn(error));
      AdMobInterstitial.requestAd().catch(error => console.warn(error));
  }

I am getting error below. All i have done like example codes here but it is not working. I have checked the build.gradle, settings.gradle, MainApplication.java. All files are same with example of this page.

screenshot_1528182380

aligenc avatar Jun 05 '18 07:06 aligenc

I am getting the same error too.

Edit: I've fixed it.

My code;

AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712'); AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());

yildiz avatar Jun 13 '18 19:06 yildiz

You can put Sample ad Unit ID for testing or Original ad Unit Id which you might be created I use sample ad unit Id here,

componentWillMount() { AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712'); AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]); AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd()); }

You can refer to this link: https://react-native-solutions.blogspot.com/2018/07/how-to-create-react-native-app-with.html

Verma-Pooja avatar Jul 13 '18 10:07 Verma-Pooja

You can put Sample ad Unit ID for testing or Original ad Unit Id which you might be created I use sample ad unit Id here,

componentWillMount() { AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712'); AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]); AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd()); }

You can refer to this link: https://react-native-solutions.blogspot.com/2018/07/how-to-create-react-native-app-with.html

I have used your example. And exactly the code (replacing the admobUnitId with mine). I am still getting the error similar to the above (undefined is not a function) - see attached snapshot.

Very strange indeed. react-native-admob:2.0.0-beta.5 image

EDITED: I have fixed the problem Basically, I still need to link the native code even while using the simulator (bugger me!) I forgot to do all the android native library linkage. Once I complete all the manual step, everything compiled and run perfectly. My mistake! Below is an example. Reply to this message if you want more details!

image

yazidIT avatar Oct 18 '18 18:10 yazidIT