AdService.ts
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import WxApi from "../wx/WxApi";
import WxBanner from "../wx/WxBanner";
import WxCustom from "../wx/WxCustom";
import WxInterstitial from "../wx/WxInterstitial";
import { GAMEDATA } from "../base/SDKConst";
import LogService from "./LogService";
import DouyinInterstitial from "../douyin/DouyinInterstitial";
export default class AdService {
private constructor() {
}
/**
* 创建banner
* @param adUnitId
* @param opts
*/
createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) {
return WxBanner.I.create(adUnitId, opts);
}
/**
* banner 显示 ps:创建默认显示
*/
showBanner() {
WxBanner.I.show()
}
/**
* banner 隐藏
*/
hideBanner() {
WxBanner.I.hide();
}
/**
* banner 销毁
*/
destoryBanner() {
WxBanner.I.destory();
}
/**
* 插屏
* @param adUnitId
*/
createInterstitialAd(adUnitId: string) {
if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
return DouyinInterstitial.showInterstitialAd(adUnitId);
} else {
return WxInterstitial.showInterstitialAd(adUnitId)
}
}
/**
* 创建原生广告
* @param adUnitId
* @param opts
*/
createCustom(adUnitId: string, opts: { top: number; left: number; adIntervals?: number }) {
return WxCustom.I.create(adUnitId, opts);
}
/**
* 原生广告 显示 ps:创建默认显示
*/
showCustom() {
WxCustom.I.show()
}
/**
* 格子广告 隐藏
*/
hideCustom() {
WxCustom.I.hide();
}
/**
* 格子广告 销毁
*/
destoryCustom() {
WxCustom.I.destory();
}
// 导出
navigateToMiniProgram(data, type, opts?) {
let { id, appid, path, game } = data;
LogService.I.jumps(id, type);
if (!path) path = `?channel_id=${GAMEDATA.channel_id}`;
return WxApi.I.navigateToMiniProgram(appid, path, opts)
}
private static instance: AdService;
static get I(): AdService {
return this.instance || (this.instance = new AdService());
}
}