How to implement Admob in Ionic?

I followed the instructions of this post: AdMob does not load ads in ion / angular application

When I launch the application through "ionic build ios && ionic emulate ios", I do not receive any ads, no black bars.

What did I miss?

thank

+2
source share
2 answers

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
    
  • index.html script ( : script, ):

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

:

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);
  });
}]);
+1

:

  • ionic platform add android ionic platform add ios
  • cordova plugin add com.rjfun.cordova.plugin.admob
  • app.js

:

$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'); });
    }
});

.

0

All Articles