小程序插屏廣告使用

小程序廣告指引:https://developers.weixin.qq.com/community/develop/doc/00060ef22cc00855a4681691c5bc01

wx.createInterstitialAd 創(chuàng)建插屏廣告組件。每調(diào)用一次該方法,返回的都是一個全新實例,該實例僅對當前頁面有效,不允許跨頁面使用
以下是封裝的方法

export default function(adUnitId) {
    this.Ad = false;    
    
    if(wx.createInterstitialAd){
        this.Ad=wx.createInterstitialAd({
            adUnitId:adUnitId
        })
    }
    
    this.show = function(opt){
        var defaul_opt = {
            show_suc:function(){ console.log('interstitial ad show suc'); },
            show_fail:function(err){ console.log('interstitial ad show fail',err); },
            close:function(){ console.log('interstitial ad close'); }
        }
        
        opt = { ...defaul_opt,...opt };
        if(!this.Ad){
            opt.show_fail('this ad is false');
            return false;
        }
        this.Ad.show().then(function(){
            opt.show_suc();
        }).catch(function(err){
            opt.show_fail(err);
        });
        
        //on close
        this.Ad.offClose();
        this.Ad.onClose(function(){
            opt.close();
        })
    }
    
}

然后我們直接調(diào)用就可以了

  • 首先我們在onload的時候創(chuàng)建一個插屏廣告對象
that.interAdObj = new interAd('adunit-fd6c6f6f5129493f');
  • 然后我們點擊的時候進行展示
this.videoAdObj.show({
    show_suc:this.show_suc,
    show_fail: show_fail,
    close:this.close
})
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。