how to check if Interstitial Ad is ready?

Hi all.

I want to show an AdMob Interstitial Ad in my app. When a button pressed, I want to check if the ad is ready.

Firstly, I wrote some lines like these to check for a state and for internet access.

export default class App extends React.Component {

  constructor(){
    super();
    this.state = {'isShown': 'no', 'isConnected': 'no'}
  }

  async componentDidMount(){
    AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
    await AdMobInterstitial.requestAdAsync();
    NetInfo.isConnected.fetch().then(isConnected => (isConnected ? this.setState({'isConnected': 'yes'}):this.setState({'isConnected': 'no'})))
  }
 
  backPressed = async () => {

    const intditiye = this.state.isShown
    const net = this.state.isConnected

    if (intditiye === 'no' && net === 'yes'){
      await AdMobInterstitial.showAdAsync()
      this.setState({isShown: 'yes'});

    } else {
      this.setState({isShown: 'no'})
      BackHandler.exitApp()
    };
    
  }

By this way, when the button pressed it checks for isShown state and then connectivity info and shows ad. After showing ad if the button pressed again, it closes the app.

I want to also check if the Interstitial ad is ready or not. So I change the code this way:

export default class App extends React.Component {

  constructor(){
    super();
    this.state = {'isShown': 'no', 'isConnected': 'no'}
  }

  async componentDidMount(){
    AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
    await AdMobInterstitial.requestAdAsync();
    NetInfo.isConnected.fetch().then(isConnected => (isConnected ? this.setState({'isConnected': 'yes'}):this.setState({'isConnected': 'no'})))
  }
 
  backPressed = async () => {
    const intditiye = this.state.isShown
    const net = this.state.isConnected
    const didLoad = AdMobInterstitial.getIsReadyAsync()

    if (intditiye === 'no' && net === 'yes' && didLoad === true){
      await AdMobInterstitial.showAdAsync()
      this.setState({isShown: 'yes'});
    } else {
      this.setState({isShown: 'no'})
      BackHandler.exitApp()
    };
    
  }

But on each time the button pressed, it closes the app. I think I am writing these lines wrongly:

    const didLoad = AdMobInterstitial.getIsReadyAsync()
 if (intditiye === 'no' && net === 'yes' && didLoad === true){

Any ideas?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.