Admob - The banner shows a black background and no

2019-05-07 01:17发布

问题:

I'm using Ionic Framework, and this plugin:

https://github.com/floatinghotpot/cordova-plugin-admob

When I deployed the app to the android phone, I see a black rectangle, but no ad.

I don't really know what's happening.. This is my code:

$ionicPlatform.ready(function() {

     //Admob
    var am = window.plugins.AdMob;
    am.createBannerView(
      {
        'publisherId': 'xxxxxxxxxx',
        'adSize': am.AD_SIZE.SMART_BANNER,
        'bannerAtTop': false
      },
      function() {
        am.requestAd(
          {
            'isTesting': true
          },
          function() {
            am.showAd(true);
          },
          function() {
            /* Handle error */
          }
        );
      },
      function() {
        /* Handle error */
      }
    );       
});

Google play services plugin is also installed when you installed the previous admob plugin. If anyone can help me, I would really appreciate it. Thanks in advance

回答1:

I noticed that you set isTesting to true. If you are using the Android simulator it may not render ads when you are in this mode.

Also make sure that you are in fact using the correct publisher id. I know it can sometimes be confusing since Admob gives a few possibilities to choose from.

I made a post on how to get Admob working with IonicFramework on my blog. It can be found here:

https://www.thepolyglotdeveloper.com/2014/06/using-admob-ionicframework/

If that still doesn't work, let us know and we can troubleshoot from there.

Cheers,



回答2:

There are 3 usual case for that black ad:

1) If you just created this adunit from admob, its possible no ad is available to be served at the moment.

2) Make sure that you have cordova.js code on the page.

<script type="text/javascript" src="./cordova.js"></script>

3) Make sure you have the plugin on your app.

call cordova plugin add https://github.com/fedmich/cordova-plugin-admob.git

or using the official git repo, https://github.com/floatinghotpot/cordova-plugin-admob