AdMob not loading ads in ionic/angular app

前端 未结 4 1108
夕颜
夕颜 2021-01-03 03:09

I\'m having some problems getting ads to work. I can\'t rap my brain around why it isn\'t working. I have the following plugins installed:

com.google.playservices 19

4条回答
  •  抹茶落季
    2021-01-03 04:04

    Raymond is right, I have used the following code to install the plugin

    > Ionic plugin add cordova-plugin-admobpro
    

    Note: Please upgrade your cordova CLI to version 5

    Open app.js and just paste the following code inside .run method and done!

    var admobid = {};
    
    // select the right Ad Id according to platform
    
    if( /(android)/i.test(navigator.userAgent) ) { 
        admobid = { // for Android
            banner: 'ca-app-pub-3940256099942544/6300978111',
            interstitial: 'ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN'
        };
    } else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
        admobid = { // for iOS
            banner: 'ca-app-pub-3940256099942544/6300978111',
            interstitial: 'ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN'
        };
    } else {
        admobid = { // for Windows Phone
            banner: 'ca-app-pub-3940256099942544/6300978111',
            interstitial: 'ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN'
        };
    }
    
    if(window.AdMob) AdMob.createBanner( {
      adId:admobid.banner, 
      isTesting: true,
      position:AdMob.AD_POSITION.BOTTOM_CENTER, 
      autoShow:true} );
    
    if(window.AdMob) AdMob.prepareInterstitial( {
      adId:admobid.interstitial, 
      autoShow:true} );
    

    Don't forget to set 'isTesting: false' while deploying your app to the store.

提交回复
热议问题