在js里面添加
// 在页面中定义激励视频广告
let videoAd = null
在Page({
data: {
里面添加
isplay:false,
不是一个部门的
onLoad: function (a) {
var t = this;
var n = this;
// 在页面onLoad回调事件中创建激励视频广告实例
if (wx.createRewardedVideoAd) {
videoAd = wx.createRewardedVideoAd({
adUnitId: 'adunit-0c3757d9bab8cf29'
})
videoAd.onLoad(() => {})
videoAd.onError((err) => {})
videoAd.onClose((res) => {
if (res && res.isEnded) {
// 正常播放结束,可以下发游戏奖励
n.setData({
isplay: true
})
}
})
// 用户点击了【关闭广告】按钮
}
},
在事件中添加
if (this.data.isplay) {
事件
} else {
const _this = this;
wx.showModal({
title: '温馨提示',
content: '须观看激励视频广告,才能解锁使用',
success(res) {
if (res.confirm) {
videoAd.show()
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
},