1

I followed the instructions of this post: AdMob not loading ads in ionic/angular app

When I run the app via "ionic build ios && ionic emulate ios" I get no ads, no black bar nothing.

What did I miss?

Thanks

Community
  • 1
  • 1
Jon
  • 55
  • 5

2 Answers2

0

Follow these steps:

  1. ionic platform add android ionic platform add ios
  2. cordova plugin add com.rjfun.cordova.plugin.admob
  3. Paste these code in run module of app.js's

code:

$ionicPlatform.ready(function() {
    if(window.plugins && window.plugins.AdMob) {
        var admob_key = device.platform == "Android" ? "ANDROID_PUBLISHER_KEY" : "IOS_PUBLISHER_KEY";
        var admob = window.plugins.AdMob;
        admob.createBannerView( {
            'publisherId': admob_key,
            'adSize': admob.AD_SIZE.BANNER,
            'bannerAtTop': false
        }, 
        function() {
            admob.requestAd({ 'isTesting': false }, 
        function() {
            admob.showAd(true);
        }, 
        function() { console.log('failed to request ad'); });
        }, 
        function() { console.log('failed to create banner view'); });
    }
});

Regards.

Miquel
  • 8,339
  • 11
  • 59
  • 82
Hardik Vaghani
  • 2,163
  • 24
  • 46
  • If you want to use more powerful and new features, please use the pro version instead. The totoally re-designed [AdMob PluginPro](https://github.com/floatinghotpot/cordova-admob-pro) is proved much better and more than welcome by Cordova APP/game developers. – Jon Jun 25 '16 at 16:12
  • Getting this error: Error: Registry returned 404 for GET on https://registry.npmjs.org/com.rjfun.cordova.plugin.admob – Umair Hamid Jul 10 '17 at 12:16
  • May be repository has been moved. You can try https://github.com/floatinghotpot/cordova-admob-pro as @Jon suggested. – Hardik Vaghani Jul 11 '17 at 03:50
0

You can follow the instructions at https://github.com/appfeel/admob-google-cordova/wiki/Angular.js,-Ionic-apps:

  • Install the plugin as usual (see here):

    ionic plugin add cordova-admob
    
  • Include the following script in your index.html (just it, no need to copy any file: the plugin is in charge to copy the script when the app is prepared):

    <script src="lib/angular-admob/angular-admob.js"></script>
    
  • Call AdMob from your Ionic app.

Here is a quick example:

var app = angular.module('myApp', ['admobModule']);

app.config(['admobSvcProvider', function (admobSvcProvider) {
  // Optionally you can configure the options here:
  admobSvcProvider.setOptions({
    publisherId:          "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",  // Required
    interstitialAdId:     "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",  // Optional
  });
}]);


app.run(['admobSvc', function (admobSvc) {
  // Also you could configure the options here (or in any controller):
  // admobSvcProvider.setOptions({ ... });

  admobSvc.createBannerView();
  // You could also call admobSvc.createBannerView(options);


  // Handle events:
  $rootScope.$on(admobSvc.events.onAdOpened, function onAdOpened(evt, e) {
    console.log('adOpened: type of ad:' + e.adType);
  });
}]);
Miquel
  • 8,339
  • 11
  • 59
  • 82