247 lines
6.9 KiB
JavaScript
247 lines
6.9 KiB
JavaScript
var i = null;
|
|
var n = null;
|
|
var a = null;
|
|
var c = null;
|
|
var s = 0;
|
|
var l = null;
|
|
function r() {
|
|
n = qg.createNativeAd({
|
|
adUnitId: "n340eelfva",
|
|
success: function (o) {
|
|
console.log("loadNativeAd loadNativeAd : success");
|
|
n.onLoad(function (o) {
|
|
console.log("原生广告加载", JSON.stringify(o.adList));
|
|
if (o && o.adList) {
|
|
var t = (a = o.adList[0]).adId;
|
|
var i = a.imgUrlList;
|
|
var s = a.icon;
|
|
var l = a.title;
|
|
var r = a.source;
|
|
c = t;
|
|
cc.loader.loadRes("textures/ysguanggao/chaping_gg", function (o, a) {
|
|
if (o) {
|
|
console.log("载入预制资源失败, 原因:" + o);
|
|
} else if (a instanceof cc.Prefab) {
|
|
var c = cc.instantiate(a);
|
|
c.parent = cc.director.getScene();
|
|
c.zIndex = cc.macro.MAX_ZINDEX;
|
|
c.group = "UI";
|
|
c.name = "nchaping";
|
|
n.reportAdShow({
|
|
adId: t
|
|
});
|
|
c.getComponent(require("gg_chaping")).InitData(i[0], s, l, r, function () {
|
|
if (null != n) {
|
|
cc.director.getScene().getChildByName("nchaping").removeFromParent();
|
|
n.offLoad();
|
|
n.offError();
|
|
n = null;
|
|
u(window.ServerConfigBd.quitShow) && d();
|
|
}
|
|
}, function () {
|
|
n.reportAdClick({
|
|
adId: t
|
|
});
|
|
setTimeout(function () {
|
|
if (null != n) {
|
|
cc.director.getScene().getChildByName("nchaping").removeFromParent();
|
|
n.offLoad();
|
|
n.offError();
|
|
n = null;
|
|
u(window.ServerConfigBd.quitShow) && setTimeout(function () {
|
|
d();
|
|
}, 500);
|
|
}
|
|
}, 1e3);
|
|
});
|
|
} else {
|
|
console.log("你载入的不是预制资源!");
|
|
}
|
|
});
|
|
}
|
|
});
|
|
n.onError(function (e) {
|
|
console.log("原生广告加载错误", JSON.stringify(e));
|
|
n.offLoad();
|
|
n.offError();
|
|
n = null;
|
|
u(window.ServerConfigBd.quitShow) && d();
|
|
});
|
|
n.load();
|
|
},
|
|
fail: function (e, o) {
|
|
console.log("loadNativeAd loadNativeAd fail: " + e + "," + o);
|
|
},
|
|
complete: function () {
|
|
console.log("loadNativeAd loadNativeAd : complete");
|
|
}
|
|
});
|
|
}
|
|
function d() {
|
|
if (null != i) {
|
|
i.destroy();
|
|
i.offError();
|
|
i.offLoad();
|
|
i.offClose();
|
|
i = null;
|
|
}
|
|
var e = qg.getSystemInfoSync();
|
|
console.log("on getSystemInfoSync: success =" + JSON.stringify(e));
|
|
var o = e.safeArea.height;
|
|
(i = qg.createBannerAd({
|
|
adUnitId: "v4hfkfhmqr",
|
|
style: {
|
|
top: o - 57,
|
|
left: 0,
|
|
height: 57,
|
|
width: 360
|
|
},
|
|
adIntervals: 60
|
|
})).onLoad();
|
|
console.log("banner加载成功");
|
|
i.show();
|
|
i.onError(function (e) {
|
|
console.log(e);
|
|
console.log("关于 banner : 普通banner报错 " + JSON.stringify(e));
|
|
i.offError();
|
|
i.offLoad();
|
|
i.offResize();
|
|
i.destroy();
|
|
i = null;
|
|
});
|
|
}
|
|
function u(e) {
|
|
return 1 + Math.floor(100 * Math.random()) <= e;
|
|
}
|
|
function h() {
|
|
if (null != i) {
|
|
i.destroy();
|
|
i.offError();
|
|
i.offLoad();
|
|
i.offClose();
|
|
i = null;
|
|
}
|
|
}
|
|
function f() {
|
|
l = qg.createRewardedVideoAd({
|
|
adUnitId: "m4znrbakb3",
|
|
success: function (e) {
|
|
console.log("华为视频广告ad demo : loadAndShowVideoAd createRewardedVideoAd: success");
|
|
l.load();
|
|
l.onLoad(function (e) {
|
|
console.log("华为视频广告ad loaded.");
|
|
});
|
|
l.onError(function (e) {
|
|
console.log(e);
|
|
l.offClose();
|
|
l.offError();
|
|
l.offLoad();
|
|
});
|
|
},
|
|
fail: function (e, o) {
|
|
console.log("华为视频广告ad demo : loadAndShowVideoAd createRewardedVideoAd fail: " + e + "," + o);
|
|
},
|
|
complete: function () {
|
|
console.log("华为视频广告ad demo : loadAndShowVideoAd createRewardedVideoAd complete");
|
|
}
|
|
});
|
|
}
|
|
module.exports = {
|
|
ShowNativeAdCreate: r,
|
|
executeShowAwardVideo: function (e, o) {
|
|
l.show();
|
|
l.onClose(function (t) {
|
|
if (t.isEnded) {
|
|
console.log("华为视频广告 激励视频完整播放后关闭");
|
|
if (e) {
|
|
e(), e = null;
|
|
}
|
|
l.offClose();
|
|
l.offError();
|
|
l.offLoad();
|
|
} else if (window.ServerConfigBd.showModal) {
|
|
qg.showModal({
|
|
title: "未观看完视频",
|
|
content: "观看完视频才能获得奖励哦",
|
|
success: function (e) {
|
|
if (e.confirm) {
|
|
l.show().then(function () {
|
|
console.log("激励视频 广告显示");
|
|
}).catch(function () {
|
|
l.load().then(function () {
|
|
l.show();
|
|
}).catch(function (e) {
|
|
if (o) {
|
|
o();
|
|
o = null;
|
|
}
|
|
l.offClose();
|
|
l.offError();
|
|
l.offLoad();
|
|
console.log("激励视频 广告显示失败");
|
|
});
|
|
});
|
|
} else if (e.cancel) {
|
|
o && (o(), o = null), l.offClose(), l.offError(), l.offLoad(), console.log("华为视频广告 激励视频中途被关闭");
|
|
}
|
|
},
|
|
fail: function (e) {
|
|
if (o) {
|
|
o();
|
|
o = null;
|
|
}
|
|
l.offClose();
|
|
l.offError();
|
|
l.offLoad();
|
|
console.log("华为视频广告 激励视频中途被关闭");
|
|
}
|
|
});
|
|
console.log("激励视频广告取消关闭,不发放奖励");
|
|
} else {
|
|
if (o) {
|
|
o(), o = null;
|
|
}
|
|
l.offClose();
|
|
l.offError();
|
|
l.offLoad();
|
|
console.log("华为视频广告 激励视频中途被关闭");
|
|
}
|
|
f();
|
|
});
|
|
},
|
|
showBanner: d,
|
|
hideBanner: h,
|
|
hwYujiazai: f,
|
|
GaiLv: u,
|
|
executeShowBanner: function () {
|
|
h();
|
|
if (++s == window.ServerConfigBd.showChapingCiShu) {
|
|
s = 0;
|
|
r();
|
|
} else {
|
|
d();
|
|
}
|
|
},
|
|
showChaPing: function () {},
|
|
executeRecorder: function () {},
|
|
stopRecorder: function () {},
|
|
executeShareRecorder: function (e, o) {},
|
|
executeShowPushBox: function () {},
|
|
isInstalledShortcut: function (e, o) {},
|
|
sendDesktopShortcut: function () {},
|
|
executeBlockAdShow: function () {},
|
|
executeShowInterstitial: function () {},
|
|
executeHideBanner: function () {},
|
|
Suijivideo: function (e, o) {},
|
|
initHuawei: function () {
|
|
qg.onShow(function () {
|
|
if (null != n && cc.director.getScene().getChildByName("nchaping")) {
|
|
console.log("进入前台上报广告" + c);
|
|
n.reportAdShow({
|
|
adId: c
|
|
});
|
|
}
|
|
});
|
|
f();
|
|
}
|
|
}; |