TkAdHelper.ets 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { ATInitConfiguration, ATSDK } from 'anythink_sdk';
  2. import { ContextHelper, IBestToast } from '../../../../../../Index';
  3. import { Singleton } from '../../../utils/ts/utils/SingleTon';
  4. import { tkBannerAd } from './TkBannerAd';
  5. import { tkInterstitialAd } from './TkInterstitialAd';
  6. import { tkRewardAd } from './TkRewardAd';
  7. import { tkStartAd } from './TkStartAd';
  8. class TkAdHelper extends Singleton {
  9. private readonly configuration: ATInitConfiguration = {
  10. appId: "a68e72d516d235",
  11. appKey: "ac0ed243c65ffeb1e16d7766bbee902dc",
  12. networkLogDebug: true
  13. }
  14. // demo
  15. // private readonly configuration: ATInitConfiguration = {
  16. // appId: "a6704d2dda04f7",
  17. // appKey: "4f7b9ac17decb9babec83aac078742c7",
  18. // networkLogDebug: true
  19. // }
  20. private readonly bannerPlacementId: string = 'b68e72d9373572'
  21. // private readonly bannerPlacementId: string = 'b6772057a769c3' //demo
  22. private readonly interstitialPlacementId: string = 'b68e72d9426e70'
  23. private readonly rewardPlacementId: string = 'b68e72d92c2b91'
  24. private readonly startPlacementId: string = 'b68e72d94e2001'
  25. private readonly nativePlacementId: string = 'b68e72d9214faf'
  26. init() {
  27. ATSDK.init(ContextHelper.oldContext.getApplicationContext(), this.configuration)
  28. ATSDK.start()
  29. .then((flag) => {
  30. if (flag) {
  31. tkRewardAd.init(this.rewardPlacementId)
  32. tkStartAd.init(this.startPlacementId)
  33. tkInterstitialAd.init(this.interstitialPlacementId)
  34. tkBannerAd.init(this.bannerPlacementId)
  35. } else {
  36. IBestToast.show("广告初始化失败")
  37. }
  38. })
  39. }
  40. showRewardAd() {
  41. tkRewardAd.showRewardAd()
  42. }
  43. showInterstitialAd() {
  44. tkInterstitialAd.showInterstitialAd()
  45. }
  46. }
  47. export const tkAdHelper = TkAdHelper.getInstance()