Class name: ATCocosSdk
| API | Parameter Description | Function Description |
|---|---|---|
| loadBannerAd | const char * placementId, cocos2d::ValueMap parameters | Used to load banner ads placementId is the ad slot id; parameters can set information for the third-party platform |
| showBannerAdInPostion | const char * placementId, std::string position | Display banner ads in the specified advertising slot at the top or bottom of the screen, position parameter: ATCocosSdk::KEY_TOP ATCocosSdk::KEY_BOTTOM |
| showBannerAdInPositionAndScenario | const char * placementId, const char * position, const char * scenario | Display banner ads in the specified advertising slot at the top or bottom of the screen, position parameter: ATCocosSdk::KEY_TOP ATCocosSdk::KEY_BOTTOM Scenario is the ad display scene, and the scene parameters can be created from the background |
| showBannerAd | const char * placementId, cocos2d::ValueMap parameters | Display banner ads in the specified ad slot parameters are the specified banner displays x coordinate, y coordinate, w width, h height |
| showBannerAdInScenario | const char * placementId, cocos2d::ValueMap parameters, const char * scenario | Display banner ads in the specified advertising slot. Parameters are the x coordinate, y coordinate, w width, and h height of the specified banner display. Scenario is the ad display scene, and the scene parameters can be created from the background |
| removeBannerAd | const char * placementId | Remove banner ads |
| isBannerAdReady | const char * placementId | Judgment designation Whether the ads in the ad slot have been loaded |
| checkBannerAdStatus | const char * placementId | Get the status of the current ad slot (Json string): 1. isLoading : Whether it is loading 2. isReady: whether there is an ad cache (same function as isBannerAdReady) 3. AdInfo: the current highest priority ad cache information |
| setBannerAdListener | ATCocosBannerAdListener * listener, const char * placementId | Set callback object |
Interface: ATCocosBannerAdListener
| API | Parameter Description | Function Description |
|---|---|---|
| onBannerAdLoadSuccess | const char * placementId | Ad loading completed |
| onBannerAdLoadFailed | const char * placementId, const char * errorString | Ad loading failed errorString failed to load Reason |
| onBannerClickedWithExtra | const char * placementId, const char * extra | The ad clicks extra contains other information about the current ad |
| onBannerShowWithExtra | const char * placementId, const char * extra | Ad display extra contains other information about the current ad |
| onBannerCloseWithExtra | const char * placementId, const char * extra | Ad close extra contains other information about the current ad |
| onBannerAutoRefreshWithExtra | const char * placementId, const char * extra | The ad auto refresh extra contains additional information about the current ad |
| onBannerAutoRefreshFailWithExtra | const char * placementId, const char * errorString, const char * extra | The ad auto refresh fail extra contains other information about the current ad errorString failed to load Reason |
1. Load banner Advertisement
ATCocosSdk::setBannerAdListener(this, bannerPlacementId);
auto glView = Director::getInstance()->getOpenGLView();
auto frameSize = glView->getFrameSize();
int width = frameSize.width;
int height = frameSize.height;
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS // IOS
std::string widthStr = StringUtils::format("%d", (int)(width/ATCocosSdk::getScreenScale()));
std::string heightStr = StringUtils::format("%d", (int)((width * 50 / 320)/ATCocosSdk::getScreenScale()));
#endif
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID // Android
std::string widthStr = StringUtils::format("%d", width);
std::string heightStr = StringUtils::format("%d", width * 50 / 320);
#endif
ValueMap customDict;
customDict[ATCocosSdk::KEY_WIDTH] = widthStr;
customDict[ATCocosSdk::KEY_HEIGHT] = heightStr;
// Adaptive banner for Admob only
customDict[ATCocosSdk::KEY_INLINE_ADAPTIVE_WIDTH] = widthStr;
customDict[ATCocosSdk::KEY_INLINE_ADAPTIVE_ORIENTATION] = ATCocosSdk::INLINE_ADAPTIVE_ORIENTATION_CURRENT;
//customDict[ATCocosSdk::KEY_INLINE_ADAPTIVE_ORIENTATION] = ATCocosSdk::INLINE_ADAPTIVE_ORIENTATION_PORTRAIT;
//customDict[ATCocosSdk::KEY_INLINE_ADAPTIVE_ORIENTATION] = ATCocosSdk::INLINE_ADAPTIVE_ORIENTATION_LANDSCAPE;
ATCocosSdk::loadBannerAd(bannerPlacementId, customDict);2. Display banner advertisement
if (ATCocosSdk::isBannerAdReady(bannerPlacementId)) {
auto glView = Director::getInstance()->getOpenGLView();
auto frameSize = glView->getFrameSize();
int width = frameSize.width;
int height = frameSize.height;
ATCocosSdk::showBannerAdInPostion(bannerPlacementId, ATCocosSdk::KEY_BOTTOM);
} else {
CCLOG("ATCocosSdk::isBannerAdReady is false");
}3. Remove banner ads
ATCocosSdk::removeBannerAd(bannerPlacementId);