Banner 및 MREC ads는 앱 레이아웃의 일부(종종 화면의 상단이나 하단, 또는 스크롤 가능한 콘텐츠 내부)를 차지하는 직사각형 광고 포맷입니다. 이 광고는 사용자가 앱과 상호작용하는 동안에도 계속 표시되므로 게임 플레이나 앱 사용을 방해하지 않으며, 설정된 시간 후에 자동으로 새로고침될 수 있습니다.
다음 섹션에서는 Banner 또는 MREC ad를 로드, 표시 및 숨기는 방법을 설명합니다.
AppLovin 블로그의 “비디오와 playable의 세상에서 모바일 Banner 광고가 지속되는 이유”를 확인해 보세요.
콘텐츠 피드 내에 MREC ads를 표시해야 하는 연동 방식의 경우, AppLovin은 다음 기법을 권장합니다.
loadAd를 호출하여 콘텐츠를 수동으로 새로고침합니다(MAAdView 인스턴스 재사용).AppLovin 데모 앱(Objective-C, Swift)에서 구현 예시를 확인할 수 있습니다.
Banner를 로드하려면 ad unit에 해당하는 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
Banner를 로드하려면 ad unit에 해당하는 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 */ }
}
Banner를 로드하려면 UIKit 뷰 타입 객체인 MAAdView를 SwiftUI 뷰 계층 구조에 통합할 수 있도록 지원하는 래퍼인 UIViewRepresentable 객체를 생성합니다.
또한 MAAdViewAdDelegate를 준수하는 래퍼 객체용 커스텀 Coordinator 클래스를 제공합니다.
이를 통해 광고가 준비되었을 때 알림을 받고, 다른 광고 관련 이벤트에 대한 알림도 받을 수 있습니다.
래퍼의 makeUIView 메서드 내부에서 ad unit에 해당하는 MAAdView 객체를 생성합니다.
해당 객체의 loadAd 메서드를 호출합니다.
해당 광고를 표시하려면 SwiftUI 뷰 계층 구조 내에 UIViewRepresentable 래퍼 객체를 추가합니다.
AppLovin-MAX_SDK_iOS GitHub 리포지토리에서 구현 예시를 확인할 수 있습니다.
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 ad
struct 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 광고를 로드하려면 ad unit에 해당하는 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 광고를 로드하려면 ad unit에 해당하는 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 광고를 로드하려면 먼저 UIKit 뷰 타입 객체인 MAAdView를 SwiftUI 뷰 계층 구조에 통합할 수 있도록 지원하는 래퍼인 UIViewRepresentable 객체를 생성합니다.
또한 MAAdViewAdDelegate를 준수하는 래퍼 객체용 커스텀 Coordinator 클래스를 제공합니다.
이를 통해 광고가 준비되었을 때 알림을 받고, 다른 광고 관련 이벤트에 대한 알림도 받을 수 있습니다.
래퍼의 makeUIView 메서드 내부에서 ad unit에 해당하는 MAAdView 객체를 생성하고 해당 객체의 loadAd 메서드를 호출합니다.
해당 광고를 표시하려면 SwiftUI 뷰 계층 구조 내에 UIViewRepresentable 래퍼 객체를 추가합니다.
AppLovin-MAX_SDK_iOS GitHub 리포지토리에서 구현 예시를 확인할 수 있습니다.
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 ad
struct 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)
}
}
더 이상 MAAdView 인스턴스가 필요하지 않을 수 있습니다.
예를 들어 사용자가 광고 제거 상품을 구매한 경우가 이에 해당합니다.
리소스 확보를 위해 이러한 MAAdView 인스턴스를 할당 해제(deallocate)하십시오.
동일한 Ad Unit ID로 여러 인스턴스를 사용하는 경우에는 MAAdView 인스턴스를 할당 해제하지 마십시오.
[self.adView removeFromSuperview];
self.adView.delegate = nil;
self.adView = nil;
adView.removeFromSuperview()
adView.delegate = nil
adView = nil
Google bidding 및 Google AdMob, Google Ad Manager, Liftoff Monetize, Pangle, Yandex는 Adaptive Banners를 지원합니다. MAX는 다른 네트워크의 Banners 크기를 비적응형(non-adaptive) 방식으로 조정합니다.
Google은 개발자가 Banner 배치 영역과 앱 콘텐츠 사이에 50 px의 패딩을 포함할 것을 권장합니다. 이렇게 하면 사용자가 실수로 Banner를 클릭할 가능성이 줄어듭니다. 자세한 정보 및 모범 사례는 Google의 “확인된 클릭 정보” 정책을 참조하십시오.
Adaptive Banners는 기기 유형 및 사용 가능한 너비에 따라 크기를 동적으로 조정하는 반응형 광고입니다. Adaptive Banners는 anchored 또는 inline 형태일 수 있으며, 각 유형은 특정 연동 요구 사항을 충족합니다.
MAX SDK 버전 13.2.0부터는 빌드 타임에 adaptiveType을 설정한 MAAdViewConfiguration 객체로 MAAdView를 초기화하여 Adaptive Banners를 연동할 수 있습니다.
다음 어댑터들은 특별한 Adaptive Banner 기능을 지원합니다.
| 네트워크 | 어댑터 버전 | 특별 기능 |
|---|---|---|
| Google Ad Manager | 11.7.0.1+ | Inline Adaptive Banners |
| 11.13.0.1+ | Inline adaptive MRECs | |
| 10.2.0.1+ | 커스텀 너비 설정 | |
| Google Bidding 및 Google AdMob | 11.7.0.1+ | Inline Adaptive Banners |
| 11.13.0.1+ | Inline adaptive MRECs | |
| 10.2.0.2+ | 커스텀 너비 설정 | |
| Liftoff Monetize | 7.4.5.1+ | |
| Pangle | 7.1.0.8.0+ | |
| Yandex | 7.12.2.1+ |
Anchored Adaptive Banners는 화면의 상단 또는 하단에 고정하는 Banner입니다. 기기 유형 및 Banner 너비에 따라 높이를 동적으로 조정합니다.
50 또는 90과 같은 고정 값을 사용하는 대신 MAAdFormat.banner.adaptiveSize.height가 반환하는 값으로 MAAdView의 높이를 설정해야 합니다.
- (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 ad
struct 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 빌더 옵션을 설정하여 포인트 단위로 커스텀 너비를 구성할 수 있습니다.
커스텀 anchored adaptive 광고에 적합한 높이를 가져오려면 adaptive size API를 호출하십시오.
CGFloat width = 400;
// Get the anchored adaptive banner height
CGFloat 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 height
let 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 height
let 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는 기본적으로 anchored 형태입니다. 스크롤 가능한 콘텐츠 내에 배치할 수 있는 Inline Adaptive Banners를 활성화할 수도 있습니다. Inline Adaptive Banners는 일반적으로 Anchored Adaptive Banners보다 큽니다. 기기 화면의 전체 높이까지 확장될 수 있는 가변적인 높이를 가집니다.
Inline Adaptive Banners를 활성화하려면 아래 코드와 같이 MAAdViewConfiguration adaptive 타입을 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
⋮
}
Inline adaptive 광고의 기본 최대 높이는 기기 화면의 전체 높이입니다.
광고가 MAAdView 높이에 맞게 표시되도록 inline adaptive 광고의 최대 높이(포인트 단위)를 설정할 수 있습니다.
예를 들어 최대 높이를 100포인트로 설정하려면 다음과 같은 코드를 사용합니다.
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
⋮
}
Inline adaptive MRECs는 기본적으로 애플리케이션 창의 전체 너비를 차지하지만, 선택적으로 포인트 단위의 커스텀 너비를 지정할 수 있습니다. 높이는 가변적이며, 최대 높이를 지정하지 않으면 표준 MREC 크기를 초과하여 기기 화면의 전체 높이까지 확장될 수 있습니다.
Inline adaptive MRECs를 활성화하려면 아래 코드와 같이 MAAdViewConfiguration adaptive 타입을 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)
}
}
로드된 adaptive 광고가 요청한 크기보다 작을 수 있습니다. 제공된 adaptive 광고의 크기에 맞게 UI를 조정하도록 구성할 수 있습니다. 이 경우 다음과 같은 코드를 사용하여 로드된 광고의 너비와 높이(포인트 단위)를 가져올 수 있습니다.
- (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
⋮
}
광고의 자동 새로고침(auto-refresh)을 중지해야 할 수 있습니다. 예를 들어 Banner 광고를 숨기거나 수동으로 새로고침하려는 경우가 이에 해당합니다. 다음 코드를 사용하여 Banner 또는 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()
다음 호출을 사용하여 Banner 또는 MREC 광고의 자동 새로고침을 시작합니다.
[adView startAutoRefresh];
adView.startAutoRefresh()
adView.startAutoRefresh()
다음 호출을 사용하여 콘텐츠를 수동으로 새로고침합니다.
loadAd()를 호출하기 전에 자동 새로고침을 중지해야 합니다.
[adView loadAd];
adView.loadAd()
adView.loadAd()