首页 > 其他分享 >处理uniapp激励广告

处理uniapp激励广告

时间:2022-11-07 15:59:05浏览次数:51  
标签:uniapp console log item 激励 广告 onCloseAdVisit videoAd

使用uniapp查看广告

getAdsItem(item) { //看广告
                // console.log(item.adTitle, item)
                if (app.getIsVisitor()) {
                    return;
                }
                if(this.isShowAd){
                    return;
                }
                if (item) { 
                    this.adItem = item;
                    this.isShowAd = true;
                    // #ifdef H5
                    this.isDownload = true;
                    // #endif
                    // #ifdef MP-WEIXIN
                    this.videoAdLoad(true);
                    // #endif
                }
            },
            videoAdLoad(flag) { //实例化广告信息
                let that = this;
                if (uni.createRewardedVideoAd) {
                    videoAd = uni.createRewardedVideoAd({
                        adUnitId: this.adItem.adUuid
                    })
                    videoAd.onLoad(() => {
                        console.log('激励视频 广告加载成功');
                    })
                    videoAd.onError((err) => {
                        console.log('onError event emit');
                        this.onCloseAdVisit();
                    })
                    videoAd.onClose((res) => {
                        // 用户点击了【关闭广告】按钮
                        videoAd.offClose();
                        if (res && res.isEnded) {
                            // 正常播放结束,可以下发游戏奖励
                            this.adVisitEnd();
                        } else {
                            // 播放中途退出,不下发游戏奖励
                        }
                        this.onCloseAdVisit();
                    })
                    if(flag){
                        this.videoAdShow(); //显示广告
                    }
                }
            },
            videoAdShow() { //显示激励广告
                if (videoAd) {
                    videoAd.show().catch(() => {
                        // 失败重试
                        videoAd.load()
                            .then(() => videoAd.show())
                            .catch(err => {
                                // console.log('激励视频 广告显示失败');
                                common.toast('广告显示失败,请重试!')
                                this.onCloseAdVisit();
                            })
                    })
                    this.adVisitStart();
                }
            },
            async adVisitStart() { //调开始看广告接口

            },
            async adVisitEnd() { //调结束看广告接口

            },
            onCloseAdVisit() { //清除广告数据
                this.adItem = {};
                this.visitId = null;
                this.isShowAd = false,
                videoAd = null;
            },

 

标签:uniapp,console,log,item,激励,广告,onCloseAdVisit,videoAd
From: https://www.cnblogs.com/czhowe/p/16866207.html

相关文章