小程序 插屏广告 使用 wx.createInterstitialAd()

注:启动小程序(即第一次需要)半分钟才可以显示插屏,两次插屏时间必须有 1 分钟

 

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

wx.createInterstitialAd 创建插屏广告组件。每调用一次该方法,返回的都是一个全新实例,该实例仅对当前页面有效,不允许跨页面使用
以下是封装的方法

 

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();
        })
    }
    
}

 

然后我们直接调用就可以了

  • 首先我们在onload的时候创建一个插屏广告对象

 

that.interAdObj = new interAd('adunit-fd6c6f6f5129493f');

 

然后我们点击的时候进行展示

 

this.videoAdObj.show({
    show_suc:()=>{},
    show_fail:()=>{},
    close:()=>{}
})

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值