cordova – 每2分钟通过Adonic在Ionic中显示插页式广告

我在Ionic中使用AdMob插件,并使用此代码显示了一个Interstital广告:

function initAd(){
     // it will display smart banner at top center,using the default options
     if(AdMob) AdMob.createBanner( {
         adId: admobid.banner,bannerId: admobid.banner,position: AdMob.AD_POSITION.BOTTOM_CENTER,autoShow: true,isTesting: false,success: function() {
             console.log('banner created');
         },error: function() {
             console.log('failed to create banner');
         }
     });


    window.AdMob.prepareInterstitial({
        adId:admobid.interstitial,autoShow:false
    });
    window.AdMob.showInterstitial();
}

有没有办法每2分钟显示一个部分广告?有人告诉我添加这个:setInterval(showInterstitial,1 * 60 * 1000),但我不知道在哪里添加?

解决方法

如果您想每2分钟显示一次,您应该使用:

setInterval(window.AdMob.showInterstitial,2*60*1000);

你应该在initAdd函数的右括号之前添加它:

function initAd(){


 // it will display smart banner at top center,using the default options
 if(AdMob) AdMob.createBanner( {
                          adId: admobid.banner,position:AdMob.AD_POSITION.BOTTOM_CENTER,success: function(){
                          console.log('banner created');
                          },error: function(){
                         console.log('failed to create banner');
                          }
                          } );

                                       window.AdMob.prepareInterstitial( 
                           {adId:admobid.interstitial,autoShow:false} );
    window.AdMob.showInterstitial();
  
  
  
  //!!!add the code here!!! - so,just paste what I wrote above:
  setInterval(window.AdMob.showInterstitial,2*60*1000);

 }

您可以在此jsFiddle example上看到一个简单的setInterval用法:

function a(){
    alert("hi every 2 seconds");
};

setInterval(a,2*1000);

你之所以不应该这样称呼它(注意a之后的括号):setInterval(a(),2 * 1000);那么你的函数只会被调用一次(你会看到只弹出一个警告). jsFiddle的例子:

function a(){
    alert("hi every 2 seconds");
};

setInterval(a(),2*1000);

希望这有助于清除一些事情.

相关文章

公司前端界面用的是vue,我要嵌入到Android中生成App第一步:...
Q:我用cordova开发项目,想在app内跳转外部链接,安装了cord...
我正在使用https://github.com/arnesson/cordova-plugin-fir...
一、Cordova的基础点在混合式应用中,我们通过现有的Cordova...
cordova自定义插件注意:存放自定义cordova插件目录不能有空...
一、问题VueAPP中有一个文件下载功能,用了各种方法来实现下...