12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- export class KuaiShouAdManager {
- private bannerAd: any;
- private rewardVideoAd: any;
- private interstitialAd: any;
- constructor() {
- this.initBannerAd();
- this.initRewardVideoAd();
- this.initInterstitialAd();
- }
- private initBannerAd() {
- let ks = (window as any)["ks"];
- if (ks.createBannerAd) {
- this.bannerAd = ks.createBannerAd({
- adUnitId: 'YOUR_BANNER_AD_ID',
- style: {
- left: 0,
- top: 0,
- width: 300
- }
- });
- this.bannerAd.onLoad(() => {
- this.bannerAd.show();
- });
- this.bannerAd.onError((err) => {
- console.log('bannerAd onError', err);
- });
- this.bannerAd.onClose(() => {
- console.log('bannerAd onClose');
- });
- }
- }
- private initRewardVideoAd() {
- let ks = (window as any)["ks"];
- if (ks.createRewardedVideoAd) {
- this.rewardVideoAd = ks.createRewardedVideoAd({
- adUnitId: 'YOUR_REWARD_VIDEO_AD_ID'
- });
- this.rewardVideoAd.onLoad(() => {
- console.log('rewardVideoAd onLoad');
- });
- this.rewardVideoAd.onError((err) => {
- console.log('rewardVideoAd onError', err);
- });
- this.rewardVideoAd.onClose((res) => {
- if (res && res.isEnded) {
- console.log('rewardVideoAd onClose, user finished video');
- } else {
- console.log('rewardVideoAd onClose, user left video');
- }
- });
- }
- }
- private initInterstitialAd() {
- let ks = (window as any)["ks"];
- if (ks.createInterstitialAd) {
- this.interstitialAd = ks.createInterstitialAd({
- adUnitId: 'YOUR_INTERSTITIAL_AD_ID'
- });
- this.interstitialAd.onLoad(() => {
- console.log('interstitialAd onLoad');
- });
- this.interstitialAd.onError((err) => {
- console.log('interstitialAd onError', err);
- });
- this.interstitialAd.onClose(() => {
- console.log('interstitialAd onClose');
- });
- }
- }
- public showRewardVideoAd(callback: Function) {
- if (this.rewardVideoAd) {
- this.rewardVideoAd.show().then(() => {
- console.log('rewardVideoAd shown successfully');
- callback();
- })
- }
- }
- public showBannerAd() {
- if (this.bannerAd) {
- this.bannerAd.show().catch((err) => {
- console.log('showBannerAd error', err);
- });
- }
- }
- public showInterstitialAd() {
- if (this.interstitialAd) {
- this.interstitialAd.show().catch((err) => {
- console.log('showInterstitialAd error', err);
- });
- }
- }
- }
|