横幅和 MREC 广告
横幅和 MREC 广告均为矩形的广告格式,会占据应用版面中的一部分,通常位于屏幕顶部或底部,有时也内嵌在可滚动的内容中。用户与应用互动时,横幅和 MREC 广告始终可见,既不会干扰或打断游戏和使用体验,也可以在指定时间周期后自动刷新。
以下各节将向您介绍如何加载、显示和隐藏横幅或 MREC 广告。
加载横幅或 MREC
横幅
要加载横幅,请创建与广告单元相对应的 MAAdView 对象并调用其 loadAd 方法。要展示该广告,请将 MAAdView 对象添加为视图层级的子视图。
实现 MAAdViewAdDelegate以便在广告就绪时收到通知。
这也会提醒您其他的广告相关事件。
#import "ExampleViewController.h"#import <AppLovinSDK/AppLovinSDK.h>
@interface ExampleViewController()<MAAdViewAdDelegate>@property (nonatomic, strong) MAAdView *adView;@end
@implementation ExampleViewController
- (void)createBannerAd{ self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"«ad-unit-ID»"]; self.adView.delegate = self;
// Banner height on iPhone and iPad is 50 and 90, respectively CGFloat height = (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) ? 90 : 50;
// Stretch to the width of the screen for banners to be fully functional CGFloat width = CGRectGetWidth(UIScreen.mainScreen.bounds);
self.adView.frame = CGRectMake(x, y, width, height);
// Set background color for banners to be fully functional self.adView.backgroundColor = «background-color»;
[self.view addSubview: self.adView];
// Load the ad [self.adView loadAd];}
#pragma mark - MAAdDelegate Protocol
- (void)didLoadAd:(MAAd *)ad {}
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error {}
- (void)didClickAd:(MAAd *)ad {}
- (void)didFailToDisplayAd:(MAAd *)ad withError:(MAError *)error {}
#pragma mark - MAAdViewAdDelegate Protocol
- (void)didExpandAd:(MAAd *)ad {}
- (void)didCollapseAd:(MAAd *)ad {}
#pragma mark - Deprecated Callbacks
- (void)didDisplayAd:(MAAd *)ad { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }- (void)didHideAd:(MAAd *)ad { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
@end要加载横幅,请创建与广告单元相对应的 MAAdView 对象并调用其 loadAd 方法。要展示该广告,请将 MAAdView 对象添加为视图层级的子视图。
实现 MAAdViewAdDelegate以便在广告就绪时收到通知。
这也会提醒您其他的广告相关事件。
class ExampleViewController: UIViewController, MAAdViewAdDelegate{ var adView: MAAdView!
func createBannerAd() { adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»") adView.delegate = self
// Banner height on iPhone and iPad is 50 and 90, respectively let height = (UIDevice.current.userInterfaceIdiom == .pad) ? 90 : 50
// Stretch to the width of the screen for banners to be fully functional let width = UIScreen.main.bounds.width
adView.frame = CGRect(x: x, y: y, width: width, height: height)
// Set background color for banners to be fully functional adView.backgroundColor = «background-color»
view.addSubview(adView)
// Load the first ad adView.loadAd() }
// MARK: MAAdDelegate Protocol
func didLoad(_ ad: MAAd) {}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {}
func didClick(_ ad: MAAd) {}
func didFail(toDisplay ad: MAAd, withError error: MAError) {}
// MARK: MAAdViewAdDelegate Protocol
func didExpand(_ ad: MAAd) {}
func didCollapse(_ ad: MAAd) {}
// MARK: Deprecated Callbacks
func didDisplay(_ ad: MAAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ } func didHide(_ ad: MAAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }}要加载横幅,请创建一个 UIViewRepresentable 对象,这是一个包装器,能让您将 MAAdView (一种 UIKit 视图类型对象) 集成到 SwiftUI 视图层级中。同时,为包装器对象提供自定义的 Coordinator 类,该类需遵循 MAAdViewAdDelegate 协议。
在广告准备就绪时它会通知您,以及通知您其他广告相关事件。
在包装器的 makeUIView 方法中创建与广告单元相对应的 MAAdView 对象。调用其 loadAd 方法。
要展示该广告,请在 SwiftUI 视图层级中添加 UIViewRepresentable 包装器对象。
您可以在 AppLovin-MAX_SDK_iOS Github 库 中找到相关实施示例。
import AppLovinSDK
struct ExampleSwiftUIWrapper: UIViewRepresentable{ func makeUIView(context: Context) -> MAAdView { let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»") adView.delegate = context.coordinator
// Set background color for banners to be fully functional adView.backgroundColor = «background-color»
// Load the first Ad adView.loadAd()
return adView }
func updateUIView(_ uiView: MAAdView, context: Context) {}
func makeCoordinator() -> Coordinator { Coordinator() }}
extension ExampleSwiftUIWrapper{ class Coordinator: NSObject, MAAdViewAdDelegate { // MARK: MAAdDelegate Protocol
func didLoad(_ ad: MAAd) {}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {}
func didClick(_ ad: MAAd) {}
func didFail(toDisplay ad: MAAd, withError error: MAError) {}
// MARK: MAAdViewAdDelegate Protocol
func didExpand(_ ad: MAAd) {}
func didCollapse(_ ad: MAAd) {}
// MARK: Deprecated Callbacks
func didDisplay(_ ad: MAAd) { /* use this for impression tracking */ } func didHide(_ ad: MAAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ } }}
// SwiftUI view to show adstruct ExampleSwiftUIBannerAdView: View{ // Banner height on iPhone and iPad is 50 and 90, respectively let height = (UIDevice.current.userInterfaceIdiom == .pad) ? 90 : 50
// Stretch to the width of the screen for banners to be fully functional let width = UIScreen.main.bounds.width
var body: some View { ExampleSwiftUIWrapper() .frame(width: width, height: height) }}MREC
要加载 MREC 广告,请创建与广告单元相对应的 MAAdView 对象,并调用其 loadAd 方法。要展示广告,请将 MAAdView 对象添加为视图层级的子视图。实现 MAAdViewAdDelegate以便在广告就绪时收到通知。这也会通知您其他广告相关事件。
#import "ExampleViewController.h"#import <AppLovinSDK/AppLovinSDK.h>
@interface ExampleViewController()<MAAdViewAdDelegate>@property (nonatomic, strong) MAAdView *adView;@end
@implementation ExampleViewController
- (void)createMRecAd{ self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"«ad-unit-ID»" adFormat: MAAdFormat.mrec]; self.adView.delegate = self;
// MREC width and height are 300 and 250 respectively, on iPhone and iPad CGFloat width = 300; CGFloat height = 250;
// Center the MREC CGFloat x = self.view.center.x - 150;
self.adView.frame = CGRectMake(x, y, width, height);
// Set background color for MREC ads to be fully functional self.adView.backgroundColor = «background-color»;
[self.view addSubview: self.adView];
// Load the ad [self.adView loadAd];}
#pragma mark - MAAdDelegate Protocol
- (void)didLoadAd:(MAAd *)ad {}
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error {}
- (void)didClickAd:(MAAd *)ad {}
- (void)didFailToDisplayAd:(MAAd *)ad withError:(MAError *)error {}
#pragma mark - MAAdViewAdDelegate Protocol
- (void)didExpandAd:(MAAd *)ad {}
- (void)didCollapseAd:(MAAd *)ad {}
#pragma mark - Deprecated Callbacks
- (void)didDisplayAd:(MAAd *)ad { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }- (void)didHideAd:(MAAd *)ad { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
@end要加载 MREC 广告,请创建与广告单元相对应的 MAAdView 对象并调用其 loadAd 方法。要展示广告,请将 MAAdView 对象添加为视图层级的子视图。实现 MAAdViewAdDelegate 以便在广告就绪时收到通知。这也会提醒您其他广告相关事件。
class ExampleViewController: UIViewController, MAAdViewAdDelegate{ var adView: MAAdView!
func createMRecAd() { adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", adFormat: MAAdFormat.mrec) adView.delegate = self
// MREC width and height are 300 and 250 respectively, on iPhone and iPad let height = 250 let width = 300
adView.frame = CGRect(x: x, y: y, width: width, height: height)
// Center the MREC adView.center.x = view.center.x
// Set background color for MREC ads to be fully functional adView.backgroundColor = «background-color»
view.addSubview(adView)
// Load the first ad adView.loadAd() }
// MARK: MAAdDelegate Protocol
func didLoad(_ ad: MAAd) {}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {}
func didClick(_ ad: MAAd) {}
func didFail(toDisplay ad: MAAd, withError error: MAError) {}
// MARK: MAAdViewAdDelegate Protocol
func didExpand(_ ad: MAAd) {}
func didCollapse(_ ad: MAAd) {}
// MARK: Deprecated Callbacks
func didDisplay(_ ad: MAAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ } func didHide(_ ad: MAAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }}要加载 MREC 广告,请首先创建一个 UIViewRepresentable 对象,这是一个包装器,允许您将 MAAdView (一种 UIKit 视图类型对象) 集成到 SwiftUI 视图层级中。同时,为包装器对象提供自定义的 Coordinator 类,该类需遵循 MAAdViewAdDelegate 协议。
广告准备就绪时会通知您,以及通知您其他广告相关事件。
在包装器的 makeUIView 方法内,创建与广告单元相对应的 MAAdView 对象并调用其 loadAd 方法。
要展示该广告,请在 SwiftUI 视图层级中添加 UIViewRepresentable 包装器对象。
您可以在 AppLovin-MAX_SDK_iOS Github 库 中找到相关实施示例。
import AppLovinSDK
struct ExampleSwiftUIWrapper: UIViewRepresentable{ func makeUIView(context: Context) -> MAAdView { let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", adFormat: MAAdFormat.mrec) adView.delegate = context.coordinator
// Set background color for banners to be fully functional adView.backgroundColor = «background-color»
// Load the first Ad adView.loadAd()
return adView }
func updateUIView(_ uiView: MAAdView, context: Context) {}
func makeCoordinator() -> Coordinator { Coordinator() }}
extension ExampleSwiftUIWrapper{ class Coordinator: NSObject, MAAdViewAdDelegate { // MARK: MAAdDelegate Protocol
func didLoad(_ ad: MAAd) {}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {}
func didClick(_ ad: MAAd) {}
func didFail(toDisplay ad: MAAd, withError error: MAError) {}
// MARK: MAAdViewAdDelegate Protocol
func didExpand(_ ad: MAAd) {}
func didCollapse(_ ad: MAAd) {}
// MARK: Deprecated Callbacks
func didDisplay(_ ad: MAAd) { /* use this for impression tracking */ } func didHide(_ ad: MAAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ } }}
// SwiftUI view to show adstruct ExampleSwiftUIMRECAdView: View{ // MREC width and height are 300 and 250 respectively, on iPhone and iPad let height = 250 let width = 300
var body: some View { ExampleSwiftUIWrapper() .frame(width: width, height: height) }}销毁横幅和 MREC 广告
You may no longer need a MAAdView instance.
This may happen, for example, if the user purchases ad removal.
Deallocate such a MAAdView instance to free resources.
如果您使用多个具有相同广告单元 ID 的实例,请不要释放 MAAdView 实例。
[self.adView removeFromSuperview];self.adView.delegate = nil;self.adView = nil;adView.removeFromSuperview()adView.delegate = niladView = nil自适应横幅广告
Adaptive banners are responsive ads that dynamically adjust their dimensions based on device type and available width. Adaptive banners can be either anchored or inline, with each type serving specific integration needs.
从 MAX SDK 13.2.0 版本开始,您可以通过在构建时设置了 adaptiveType 的 MAAdViewConfiguration 对象来初始化 MAAdView,从而集成自适应横幅。
广告平台适配器对自适应横幅功能的支持
以下适配器对特殊自适应横幅功能的支持:
| 平台 | 特殊功能 | 适配器版本 |
|---|---|---|
| Google Ad Manager | 内嵌自适应横幅 | 11.7.0.1+ |
| 内嵌自适应 MREC 广告 | 11.13.0.1+ | |
| 设置自定义宽度 | 10.2.0.1+ | |
| Google 竞价和 Google AdMob | 内嵌自适应横幅 | 11.7.0.1+ |
| 内嵌自适应 MREC 广告 | 11.13.0.1+ | |
| 设置自定义宽度 | 10.2.0.2+ | |
| Liftoff Monetize | 内嵌自适应横幅 | 7.4.5.1+ |
| 内嵌自适应 MREC | 7.4.5.1+ | |
| 设置自定义宽度 | 7.4.5.1+ |
锚定式自适应横幅
锚定式自适应横幅是指固定在屏幕顶部或底部的广告形式,根据设备类型和横幅宽度动态调整高度。
您必须将 MAAdView 的高度设置为 MAAdFormat.banner.adaptiveSize.height 返回的值,而不是使用 50 或 90 等常量值。
- (void)createAnchoredAdaptiveBannerAd{ // Stretch to the width of the screen for banners to be fully functional CGFloat width = CGRectGetWidth(UIScreen.mainScreen.bounds);
// Get the anchored adaptive banner height CGFloat height = MAAdFormat.banner.adaptiveSize.height;
MAAdViewConfiguration *config = [MAAdViewConfiguration configurationWithBuilderBlock:^(MAAdViewConfigurationBuilder *builder) { builder.adaptiveType = MAAdViewAdaptiveTypeAnchored; }];
self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"«ad-unit-ID»" configuration: config]; self.adView.delegate = self;
self.adView.frame = CGRectMake(x, y, width, height);
// Set background color for banners to be fully functional self.adView.backgroundColor = «background-color»;
[self.view addSubview: self.adView];
// Load the ad [self.adView loadAd];}func createAnchoredAdaptiveBannerAd(){ // Stretch to the width of the screen for banners to be fully functional let width = UIScreen.main.bounds.width
// Get the anchored adaptive banner height. let height = MAAdFormat.banner.adaptiveSize.height
let config = MAAdViewConfiguration { builder in builder.adaptiveType = .anchored } adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", configuration: config) adView.delegate = self
adView.frame = CGRect(x: x, y: y, width: width, height: height)
// Set background color for banners to be fully functional adView.backgroundColor = «background-color»
view.addSubview(adView)
// Load the first ad adView.loadAd()}struct ExampleSwiftUIWrapper: UIViewRepresentable{ func makeUIView(context: Context) -> MAAdView { let config = MAAdViewConfiguration { builder in builder.adaptiveType = .anchored } let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", configuration: config) adView.delegate = context.coordinator
// Set background color for banners to be fully functional adView.backgroundColor = «background-color»
// Load the first Ad adView.loadAd()
return adView } ⋮}
// SwiftUI view to show adstruct ExampleSwiftUIAdaptiveBannerAdView: View{ // Stretch to the width of the screen for banners to be fully functional let width = UIScreen.main.bounds.width
// Get the anchored adaptive banner height let height = MAAdFormat.banner.adaptiveSize.height
var body: some View { ExampleSwiftUIWrapper() .frame(width: width, height: height) }}设置自定义宽度
对于更具体的集成,您可以通过设置 MAAdViewConfiguration 构建器选项,以 points 为单位配置自定义宽度。要为自定义的锚定式自适应广告调取合适的高度,请调用自适应尺寸 API。
CGFloat width = 400;
// Get the anchored adaptive banner heightCGFloat height = [self.adView.adFormat adapativeSizeForWidth: width].height;
MAAdViewConfiguration *config = [MAAdViewConfiguration configurationWithBuilderBlock:^(MAAdViewConfigurationBuilder *builder) { builder.adaptiveType = MAAdViewAdaptiveTypeAnchored; builder.adaptiveWidth = width;}];self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"«ad-unit-ID»" configuration: config];let width = 400
// Get the anchored adaptive banner heightlet height = adView.adFormat.adaptiveSize(forWidth: width).height
let config = MAAdViewConfiguration { builder in builder.adaptiveType = .anchored builder.adaptiveWidth = width}adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", configuration: config)let width = 400
// Get the anchored adaptive banner heightlet height = adView.adFormat.adaptiveSize(forWidth: width).height
let config = MAAdViewConfiguration { builder in builder.adaptiveType = .anchored builder.adaptiveWidth = width}let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", configuration: config)⋮内嵌自适应横幅
Adaptive banners are anchored by default. You can also enable inline adaptive banners, which you can place in scrollable content. Inline adaptive banners are typically larger than anchored adaptive banners. They have variable heights that can extend to the full height of the device screen.
要启用内嵌自适应横幅,请将 MAAdViewConfiguration 自适应类型设置为 MAAdViewAdaptiveTypeInline,如以下代码所示:
MAAdViewConfiguration *config = [MAAdViewConfiguration configurationWithBuilderBlock:^(MAAdViewConfigurationBuilder *builder) { builder.adaptiveType = MAAdViewAdaptiveTypeInline; ⋮}];let config = MAAdViewConfiguration { builder in builder.adaptiveType = .inline ⋮}let config = MAAdViewConfiguration { builder in builder.adaptiveType = .inline ⋮}The default maximum height for an inline adaptive ad is the entire height of the device screen.
You may want to set a maximum height, in points, for your inline adaptive ad to ensure that the ad fits in the height of the MAAdView.
You can do this with code like the following, which uses a maximum height of 100 points as an example:
MAAdViewConfiguration *config = [MAAdViewConfiguration configurationWithBuilderBlock:^(MAAdViewConfigurationBuilder *builder) { builder.adaptiveType = MAAdViewAdaptiveTypeInline; builder.inlineMaximumHeight = 100; ⋮}];let config = MAAdViewConfiguration { builder in builder.adaptiveType = .inline builder.inlineMaximumHeight = 100 ⋮}let config = MAAdViewConfiguration { builder in builder.adaptiveType = .inline builder.inlineMaximumHeight = 100 ⋮}内嵌自适应 MREC
内嵌自适应 MREC 默认覆盖整个应用程序窗口宽度,但您也可以指定自定义宽度 (以 points 为单位)。该高度可变,如果您未指定最大高度,则该变量会超出标准的 MREC 广告尺寸,最高可达设备屏幕的完整高度。
要启用内嵌自适应 MREC,请将 MAAdViewConfiguration 自适应类型设置为 MAAdViewAdaptiveTypeInline,如以下代码所示:
- (void)createInlineAdaptiveMRecAd{ // Set a custom width, in points, for the inline adaptive MREC. Otherwise stretch to screen width by using CGRectGetWidth(UIScreen.mainScreen.bounds) CGFloat width = 400;
// Set a maximum height, in points, for the inline adaptive MREC. Otherwise use standard MREC height of 250 points // Google recommends a height greater than 50 points, with a minimum of 32 points and a maximum equal to the screen height // The value must also not exceed the height of the MAAdView CGFloat height = 300;
MAAdViewConfiguration *config = [MAAdViewConfiguration configurationWithBuilderBlock:^(MAAdViewConfigurationBuilder *builder) { builder.adaptiveType = MAAdViewAdaptiveTypeInline; builder.adaptiveWidth = width; // Optional: The adaptive ad spans the width of the application window if you do not set a value builder.inlineMaximumHeight = height; // Optional: The maximum height is the screen height if you do not set a value }]; self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"«ad-unit-ID»" adFormat: MAAdFormat.mrec configuration: config]; self.adView.delegate = self;
self.adView.frame = CGRectMake(x, y, width, height);
// Set background color for adaptive MRECs to be fully functional self.adView.backgroundColor = «background-color»;
[self.view addSubview: self.adView];
// Load the ad [self.adView loadAd];}func createInlineAdaptiveMRecAd(){ // Set a custom width, in points, for the inline adaptive MREC. Otherwise stretch to screen width by using UIScreen.main.bounds.width let width = 400
// Set a maximum height, in points, for the inline adaptive MREC. Otherwise use standard MREC height of 250 points // Google recommends a height greater than 50 points, with a minimum of 32 points and a maximum equal to the screen height // The value must also not exceed the height of the MAAdView let height = 300
let config = MAAdViewConfiguration { builder in builder.adaptiveType = .inline builder.adaptiveWidth = width // Optional: The adaptive ad spans the width of the application window if you do not set a value builder.inlineMaximumHeight = height // Optional: The maximum height is the screen height if you do not set a value } adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", adFormat: MAAdFormat.mrec, configuration: config) adView.delegate = self
adView.frame = CGRect(x: x, y: y, width: width, height: height)
// Set background color for adaptive MRECs to be fully functional adView.backgroundColor = «background-color»
view.addSubview(adView)
// Load the first ad adView.loadAd()}struct ExampleSwiftUIWrapper: UIViewRepresentable{ let width: CGFloat let height: CGFloat
func makeUIView(context: Context) -> MAAdView { let config = MAAdViewConfiguration { builder in builder.adaptiveType = .inline builder.adaptiveWidth = width // Optional: The adaptive ad spans the width of the application window if you do not set a value builder.inlineMaximumHeight = height // Optional: The maximum height is the screen height if you do not set a value } let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", adFormat: MAAdFormat.mrec, configuration: config) adView.delegate = context.coordinator
// Set background color for adaptive MRECs to be fully functional adView.backgroundColor = «background-color»
// Load the first ad adView.loadAd()
return adView } ⋮}
struct ExampleSwiftUIInlineAdaptiveMRecAdView: View{ // Set a custom width, in points, for the inline adaptive MREC. Otherwise stretch to screen width by using UIScreen.main.bounds.width let width = 400
// Set a maximum height, in points, for the inline adaptive MREC. Otherwise use standard MREC height of 250 points // Google recommends a height greater than 50 points, with a minimum of 32 points and a maximum equal to the screen height // The value must also not exceed the height of the MAAdView let height = 300
var body: some View { ExampleSwiftUIWrapper(width: width, height: height) .frame(width: width, height: height) }}处理自适应广告尺寸
您加载的自适应广告可能小于您请求的尺寸。您可能希望根据所展示的自适应广告的尺寸,配置 UI 以实现相应的适配。那么请使用如下代码,获取已加载广告的宽度和高度 (以 point 为单位):
- (void)didLoadAd:(MAAd *)ad{ CGSize adViewSize = ad.size; CGFloat width = adViewSize.width; CGFloat height = adViewSize.height; ⋮}func didLoad(_ ad: MAAd){ let adViewSize = ad.size let width = adViewSize.width let height = adViewSize.height ⋮}func didLoad(_ ad: MAAd){ let adViewSize = ad.size let width = adViewSize.width let height = adViewSize.height ⋮}停止和启动自动刷新
您可能想要停止广告的自动刷新。 例如,当您隐藏横幅广告或想要手动刷新时,您可能想要这样做。 使用以下代码停止横幅或 MREC 广告的自动刷新:
// Set this extra parameter to work around SDK bug that ignores calls to stopAutoRefresh()[adView setExtraParameterForKey: @"allow_pause_auto_refresh_immediately" value: @"true"];[adView stopAutoRefresh];// Set this extra parameter to work around SDK bug that ignores calls to stopAutoRefresh()adView.setExtraParameterForKey("allow_pause_auto_refresh_immediately", value: "true")adView.stopAutoRefresh()// Set this extra parameter to work around SDK bug that ignores calls to stopAutoRefresh()adView.setExtraParameterForKey("allow_pause_auto_refresh_immediately", value: "true")adView.stopAutoRefresh()使用以下调用启动横幅或 MREC 广告的自动刷新:
[adView startAutoRefresh];adView.startAutoRefresh()adView.startAutoRefresh()使用以下调用手动刷新内容。
在调用 loadAd() 之前您必须停止自动刷新。
[adView loadAd];adView.loadAd()adView.loadAd()