コンテンツにスキップ

バナー&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

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 インスタンスが不要になることがあります。 例えば、ユーザーが広告削除を購入した場合などがこれに該当します。 この場合、MAAdView インスタンスの割り当てを解除して、リソースを解放してください。

ただし、同じ広告ユニットIDを持つ複数のインスタンスを使用している場合は、MAAdView インスタンスの割り当てを解除しないでください。

[self.adView removeFromSuperview];
self.adView.delegate = nil;
self.adView = nil;

アダプティブバナー

Adaptive banners are responsive ads that dynamically adjust their dimensions based on device type and available width. Adaptive banners can either be anchored or inline, with each type serving specific integration needs.

Starting in MAX SDK version 13.2.0, you can integrate adaptive banners by initializing your MAAdView with a MAAdViewConfiguration object.

Anchored Adaptive Banners

Anchored adaptive banners are those you anchor at the top or bottom of the screen. They dynamically adjust their height based on the device type and the banner width.

You must set the height of the MAAdView to the value returned by MAAdFormat.banner.adaptiveSize.height instead of using a constant value like 50 or 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];
}

カスタム幅を設定する

For more specific integrations, you can configure a custom width in points by calling a MAAdViewConfiguration builder method (as of Google adapter version 10.2.0.2, Google Ad Manager adapter version 10.2.0.1, and Liftoff Monetize adapter version 7.4.5.1). To fetch the appropriate height for your custom anchored adaptive ad, call the 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];

インラインアダプティブバナー

Adaptive banners are anchored by default. Alternatively, you can 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.

Inline adaptive banners are supported starting with iOS Google adapters version 11.7.0.1 and Liftoff Monetize adapter version 7.4.5.1. To enable inline adaptive banners, set the MAAdViewConfiguration adaptive type to MAAdViewAdaptiveTypeInline as shown in the code below:

MAAdViewConfiguration *config = [MAAdViewConfiguration configurationWithBuilderBlock:^(MAAdViewConfigurationBuilder *builder) {
builder.adaptiveType = MAAdViewAdaptiveTypeInline;
}];

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 is within 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;
}];

Inline Adaptive MRECs

You can integrate inline adaptive MRECs, starting with iOS Google adapters version 11.13.0.1 and Liftoff Monetize adapter version 7.4.5.1. You must set inline adaptive MRECs to the type MAAdViewAdaptiveTypeInline for them to function properly.

Inline adaptive MRECs span the full width of the application window by default, but you may optionally specify a custom width in points. The height is variable and can extend beyond standard MREC dimensions up to the full height of the device screen if you do not specify a maximum height. You configure an inline adaptive MREC as shown in the following example:

- (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 will span the width of the application window if you do not set a value
builder.inlineMaximumHeight = height; // Optional: The maximum height will be 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];
}

Handling Adaptive Ad Sizes

The adaptive ad you load could be smaller than the dimensions you requested. You may wish to configure your UI in a way that can adapt based on the size of the adaptive ad served. If so, you can retrieve the width and height of the loaded ad, in points, with code like the following:

- (void)didLoadAd:(MAAd *)ad
{
CGSize adViewSize = ad.size;
CGFloat width = adViewSize.width;
CGFloat 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];

バナー広告または MREC 広告の自動更新を開始するには、次の呼び出しが必要です。

[adView startAutoRefresh];

次の呼び出しを行うと、コンテンツを手動で更新できます。 loadAd() を呼び出す前に、自動更新を停止する必要があります。

[adView loadAd];