跳转到内容

Banner & MREC Ads

此内容尚不支持你的语言。

The following sections show you how to load and then show and hide a banner or MREC ad.

Loading a Banner or MREC

The following code shows you how to load a banner or MREC by using your Ad Unit ID, desired position, and (for banners) desired background color. MAX will size the ad for you automatically:

const BANNER_AD_UNIT_IDS = {
"android" : "«Android-banner-ad-unit-ID»",
"ios" : "«iOS-banner-ad-unit-ID»"
}
func initializeBannerAds:
var platform = OS.get_name().to_lower() # "android", "ios", etc.
var ad_unit_id = adUnitsDict.get(platform)
# MAX automatically sizes banners to 320×50 on phones and 728×90 on tablets
AppLovinMAX.create_banner(ad_unit_id, AppLovinMAX.BannerPosition.BOTTOM_CENTER)

Displaying a Banner or MREC

To show a banner or MREC, make the following call:

AppLovinMAX.show_banner(«ad-unit-ID»);

To hide a banner or MREC, make the following call:

AppLovinMAX.hide_banner(«ad-unit-ID»);

Adaptive Banners

Adaptive banners are responsive banners with heights that derive from the device type and the width of the banner. To disable adaptive banners, set the adaptive_banner flag, as in this example:

AppLovinMAX.set_banner_extra_parameter(«ad-unit-ID», "adaptive_banner", "false")

Call AppLovinMAX.get_adaptive_banner_height_for_width(«width») to get the banner height, and then adjust your content accordingly.

Stopping and Starting Auto-Refresh

You may want to stop auto-refresh for an ad. This may be the case when you hide an ad or you want to manually refresh. Stop auto-refresh with the following call:

AppLovinMAX.stop_banner_auto_refresh(«ad-unit-ID»);

Start auto-refresh for an ad with the following call:

AppLovinMAX.start_banner_auto_refresh(«ad-unit-ID»);