React-native-firebase: Admob iOS: Something happened internally error

Created on 4 Jul 2017  路  12Comments  路  Source: invertase/react-native-firebase

When I show an interstitial ad, close it, then try load a new one, onAdFailedToLoad is called with the following:

Error: Something happened internally; for instance, an invalid response was received from the ad server.

Works fine on Android, but on iOS it keeps giving this error when trying to show the second interstitial.

Anyone have any ideas?

export default class Page {

  interstitial = null;

  static InterstitialPreload(){

        this.interstitial = firebase.admob().interstitial(settings.admob_ad_unit_id_interstitial);

        this.interstitial.on('onAdLoaded', () => {
            console.warn('Advert ready to show.'); //ad is shown via .show in another function

        });

        this.interstitial.on('onAdOpened', () => {
            console.warn('Advert opened.');
        });

        this.interstitial.on('onAdClosed', () => {
            console.warn('onAdClosed');
            setTimeout(function(){
                Page.InterstitialPreload();
            },2000);
        });

        this.interstitial.on('onAdFailedToLoad', (err) => {
            console.warn('onAdFailedToLoad: '+err);
            console.error(err);
        });
    //}

    this.interstitial_request = new firebase.admob.AdRequest();
    this.interstitial_request.addKeyword('dagligkrydsen-interstitial');//.addKeyword('bar');

    // Load the advert with our AdRequest
    this.interstitial.loadAd(this.interstitial_request.build());

  }
}
AdMob

Most helpful comment

Almost two years forward, still facing this issue.

    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-native-firebase": "^5.2.2",

and

  pod 'Firebase/Core', '~> 5.15.0'
  pod 'Firebase/AdMob', '~> 5.15.0'

Note that I am using this with Admob test IDs for IOS.

All 12 comments

Just saw this in device console:
Request Error: Will not send request because interstitial object has been used.

How am I supposed to create a new interstitial ?

Hello @bitfabrikken

Could you open the project in XCode and add a line debug here: https://github.com/invertase/react-native-firebase/blob/master/ios/RNFirebase/admob/RNFirebaseAdMobInterstitial.m#L18

It should be creating a new instance of GADInterstitial on every init via initWithProps. Please let me know if it gets to that breakpoint a second time.

Ah, I just noticed something different between the Android & iOS SDKs:

Android: A single InterstitialAd object can be used to request and display multiple interstitial ads over the course of an activity's lifespan, so you only need to construct it once.

iOS: GADInterstitial is a single-use object that will load and display one interstitial ad. To display multiple interstitial ads, an app needs to create a GADInterstitial for each one.

I'll add something in for this!

Thank you @Ehesp !! I did what you asked, and it doesn't get to that line 18 point a second time.

@bitfabrikken could you install this commit with NPM: https://github.com/invertase/react-native-firebase/commit/92b3860230c7ba13dda93c1dced21ca74bc81a0a

Let me know if it works, especially with the events. Tried it locally and seems too :)

@bitfabrikken fix released in v2.0.1

@Ehesp That's some fast work :) But I think something's still wrong.

I installed with "npm install --save [email protected]" (for future reference, I couldn't figure out how to install a specific commit via NPM)

It now seems to work, but I think the eventlisteners aren't getting cleared.
For instance, the below code will type out "Advert ready to show" 1 time the first time, 2 times the second, 4 times the next, 8 times the next, and so on.

Maybe I'm just doing something wrong, but I've tried many different approaches, so I dunno.
The "do_add_listeners" part of the code below seems to have zero impact.

global.interstitial = null;
export default class Pages{


  static InterstitialPreload(){

     //if interstitial already exists from previously, do not add new eventlisteners
     var do_add_listeners = true;
     if (interstitial) do_add_listeners = false;


    interstitial = firebase.admob().interstitial(settings.admob_ad_unit_id_interstitial);

    if (do_add_listeners){

        interstitial.on('onAdLoaded', () => {
            console.warn("Advert ready to show.");
        });

        interstitial.on('onAdOpened', () => {
            console.warn('Advert opened.');
        });


        interstitial.on('onAdClosed', () => {
            console.warn("onAdClosed");
            Pages.InterstitialPreload(); //preload again :)
        });

        interstitial.on('onAdFailedToLoad', (err) => {
            console.warn('onAdFailedToLoad: '+err.code);
        });

    }

    var request = new firebase.admob.AdRequest();
    request.addKeyword('somekeyword');

    interstitial.loadAd(request.build());

  }

@Ehesp any updates on your progress? Please let me know if you need any further info :)

@bitfabrikken Try this commit out: https://github.com/invertase/react-native-firebase/commit/22e511209aaa0fae1d68e6ec839f076188c76f04

You can install it via NPM by doing:

"react-native-firebase": "git://github.com/invertase/react-native-firebase.git#d4328f3adbb1fd19e0a8c3b28ba5ffed49780b51"

Its a temporary fix, @Salakar is working on multi-app support at the moment which overhauls the event emitters internally which will handle this sort of thing.

@Ehsep It works like a charm now! Thank you!

Awesome :)

Almost two years forward, still facing this issue.

    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-native-firebase": "^5.2.2",

and

  pod 'Firebase/Core', '~> 5.15.0'
  pod 'Firebase/AdMob', '~> 5.15.0'

Note that I am using this with Admob test IDs for IOS.

Was this page helpful?
0 / 5 - 0 ratings