代码在最下面
按照图示即可添加激励广告
演示小程序:
代码
// 在页面中定义激励视频广告
let videoAd = null
=================
Page({添加
isplay: false,
=================
事件
if (this.data.isplay) {
} else {
const _this = this;
tt.showModal({
title: '系统提示',
content: '首次使用须观看激励视频广告,才能解锁使用',
success(res) {
if (res.confirm) {
videoAd.show()
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
},
===============
onLoad: function (a) {
var t = this;
var n = this;
// 在页面onLoad回调事件中创建激励视频广告实例
if (tt.createRewardedVideoAd) {
videoAd = tt.createRewardedVideoAd({
adUnitId: '你的广告ID'
})
videoAd.onLoad(() => {})
videoAd.onError((err) => {})
videoAd.onClose((res) => {
if (res && res.isEnded) {
// 正常播放结束,可以下发游戏奖励
n.setData({
isplay: true
})
}
})
// 用户点击了【关闭广告】按钮
}
},