目前我用的是Uniapp框架开发小程序,最近有些用户(已知有2个)加载不了我小程序的所有激励广告,但是我自己的微信和别人的微信有可以加载。
还好我针对这个问题,在代码上记录了加载失败的日志传送给后端。
然后我还问了那个用户是不是用Iphone手机,他说不是,用的安卓。我自己手机也是安卓
下面是打印的日志信息:

我的小程序前端页面代码是这样的:
首先是initAdver函数,在页面onLoad时候会去调用。,recordLog函数是将广告加载失败的问题记录到数据库里面
//初始化广告信息
initAdver(){
console.log("initAdver")
var that = this;
this.isLoadAd = false
console.log("ad为:",getApp().globalData.adverInfo.rewardedVideoAd )
this.rewardedVideoAd = uni.createRewardedVideoAd({ adUnitId: getApp().globalData.adverInfo.rewardedVideoAd })
this.rewardedVideoAd.onLoad(res => {
// 当激励视频被关闭时,默认预载下一条数据,加载完成时仍然触发 `onLoad` 事件
that.isLoadAd = true
console.log('onLoad event')
})
this.rewardedVideoAd.onError((err) => {
console.log('onError event', err);
recordLog({"module":"广告模块","api":"uni.createRewardedVideoAd","content":"页面调用initAdver,广告加载时候,发生onError","res":JSON.stringify(err) })
})
// 用户点击了【关闭广告】按钮
this.rewardedVideoAd.onClose((res) => {
var that = this;
if (res && res.isEnded) {
// 正常播放结束
// 这里应该联网给予用户激励。且这段代码应该做安全保护,详见下文中的“安全注意”
console.log("奖励开始发送")
this.toReward();
} else {
// 播放中途退出
console.log('播放中途退出')
}
})
},
showRewardedVideo函数是当用户点击要看广告的时候触发的,recordLog函数是将广告加载失败的问题记录到数据库里面
showRewardedVideo() {
var that = this;
//显示广告提示语
uni.showModal({
title:'提示',
content:getApp().globalData.adverInfo.tip,
success(res){
if(res.confirm){
if (that.isLoadAd) {
that.rewardedVideoAd.show().catch(err=>{
//失败重试
that.rewardedVideoAd.load()
.then(() => that.rewardedVideoAd.show())
.catch(err => {
uni.showToast({
title:'广告加载失败,请刷新本页面或者联系管理员哦~',
icon:'none'
})
console.log('激励视频 广告显示失败')
recordLog({"module":"广告模块","api":"rewardedVideoAd.show()","content":"that.isLoadAd为true,that.rewardedVideoAd.show().catch触发","res":JSON.stringify(err)})
})
})
}else{
that.rewardedVideoAd.load()
.then(() => that.rewardedVideoAd.show())
.catch(err => {
uni.showToast({
title:'广告加载失败,请刷新本页面或者联系管理员哦~',
icon:'none'
})
recordLog({"module":"广告模块","api":"rewardedVideoAd.show()","content":"that.isLoadAd为true,that.rewardedVideoAd.show().catch触发","res":JSON.stringify(err)})
})
}
}
},
fail(err){
console.log(err)
}
})
}
各位可以看看什么问题吗,我自己开发的两个小程序都时不时有这个问题,不知道是腾讯本身广告API的问题,还是我自己代码的问题,很苦恼
