EddyVerbruggen / nativescript-admob

NativeScript plugin to earn some precious :moneybag::moneybag: with ads by Google AdMob
MIT License
69 stars 26 forks source link

Adding a banner & tapping overview button quickly , causes exception #33

Closed RoyiNamir closed 6 years ago

RoyiNamir commented 6 years ago

In my app ( also in the code itself) - we use timeout - to show the ad.

However - i've noticed a rare scenario where If I navigate (angular) to a screen which in its ngOninit has this :

 setTimeout(() =>
                       {
                           this._admobService.createBanner();
                       }, 3000);

image

It's probably becuase it can't find anything to put the banner on.

Is there a check that can be made in our code - not to cause exception ?

EddyVerbruggen commented 6 years ago

I've applied the fix you proposed to check for existence of those properties. See #36.

RoyiNamir commented 6 years ago

@EddyVerbruggen Hi.

If you want , It should be added also in the Hidebanner function.

admob.hideBanner = function (arg) {
  return new Promise(function (resolve, reject) {
    try {
      if (admob.adView != null) {   
        var parent = admob && admob.adView && admob.adView.getParent();   //<------

/* And also - removed one "=" becuase it's undefined , 
so we DO want to compare null to undefined . 
It was before `!==` and nul !==undefined so it tried to [do this](https://i.imgur.com/7Qxnarj.jpg)
*/
        if (parent != null) {      // <-------
          parent.removeView(admob.adView);
        }
        admob.adView = null;
      }
      resolve();
    } catch (ex) {
      console.log("Error in admob.hideBanner: " + ex);
      reject(ex);
    }
  });
};

image