⚠️ Please note that the unit of size passed in for iOS and Android platforms may differ and may require conversion.
typescript Copyimport {ATBannerSDK} from "db://assets/script/AnyThinkAds/ATBanner"; const setting = {}; setting[ATBannerSDK.kATBannerAdLoadingExtraBannerAdSizeStruct] = ATBannerSDK.createLoadAdSize(cc.screen.windowSize.width, 300); ATBannerSDK.loadAd("your placement id", setting);
⚠️ Note: On the iOS platform, if you need to use Admob's adaptive banner settings, you need to add the following code to
setting
:typescript Copysetting[ATBannerSDK.kATBannerAdAdaptiveWidth] = cc.screen.windowSize.width; setting[ATBannerSDK.kATBannerAdAdaptiveOrientation] = ATBannerSDK.kATBannerAdAdaptiveOrientationPortrait;
And uncomment the OC code as shown in the figure (iOS platform Admob adaptive size related code)
private BannerAdListener = {
onBannerAdLoaded: (placementId: any) => {
console.log("onBannerAdLoaded", placementId)
},
onBannerAdLoadFail: (placementId: any, errorInfo: any) => {
console.log("onBannerAdLoadFail", placementId, errorInfo)
},
onBannerAdShow: (placementId: any, callbackInfo: any) => {
console.log("onBannerAdShow", placementId, callbackInfo)
},
onBannerAdClick: (placementId: any, callbackInfo: any) => {
console.log("onBannerAdClick", placementId, callbackInfo)
},
onBannerAdAutoRefresh: (placementId: any, callbackInfo: any) => {
console.log("onBannerAdAutoRefresh", placementId, callbackInfo)
},
onBannerAdAutoRefreshFail: (placementId: any, errorInfo: any) => {
console.log("onBannerAdAutoRefreshFail", placementId, errorInfo)
},
onBannerAdCloseButtonTapped: (placementId: any, callbackInfo: any) => {
console.log("onBannerAdCloseButtonTapped", placementId, callbackInfo)
}
};
ATBannerSDK.setAdListener(this.BannerAdListener);
ATBannerSDK.entryAdScenario("your placement id", "your scenario id");
if (ATBannerSDK.hasAdReady("your placement id")) {
ATBannerSDK.showAdInPositionAndScenario("your placement id", ATBannerSDK.kATBannerAdShowingPositionBottom, "your scenario id");
} else {
const setting = {};
setting[ATBannerSDK.kATBannerAdLoadingExtraBannerAdSizeStruct] = ATBannerSDK.createLoadAdSize(cc.screen.windowSize.width, 300);
ATBannerSDK.loadAd("your placement id", setting);
}