コンテンツにスキップ

MAX メディエーションネットワークの手動ダウンロード

リリースアップデートを受け取るには、AppLovin-MAX-SDK-iOS GitHub repository をサブスクライブしてください。

最新のiOS SDKをダウンロード

AppLovin SDKを連携

ダウンロードされたzipファイルにはAppLovinSDK.xcframeworkファイルが含まれています。 SDKをアプリに追加するには、AppLovinSDK.xcframeworkファイルをXcodeプロジェクトにドラッグします。 Xcodeプロジェクトのターゲット設定のFrameworks, Libraries, and Embedded ContentセクションにAppLovinSDK.xcframeworkが含まれていることを確認してください。

Xcodeフラグを有効化

AppLovin SDKをコンパイルするには、-ObjC フラグを追加する必要があります。 -ObjC フラグを有効にするには、File > Project Settingsを選択し、Build Settingsに移動します。次にOther Linker Flagsを検索し、+をクリックして -ObjC を追加します。

フレームワークを追加

プロジェクトに以下のフレームワークをリンクしてください:

  • AdSupport
  • AppTrackingTransparency
  • AudioToolbox
  • AVFoundation
  • CoreGraphics
  • CoreMedia
  • CoreMotion
  • CoreTelephony
  • Foundation
  • MessageUI
  • libz
  • SafariServices
  • StoreKit
  • SystemConfiguration
  • UIKit
  • WebKit

Ad Reviewを有効化

MAX Ad Reviewサービスを有効化するには、AppLovinQualityServiceSetup-ios.rbをダウンロードしてプロジェクトフォルダに移動します。 それからターミナルウィンドウを開き、cd をプロジェクトディレクトリに移動して以下を実行します。

Terminal window
ruby AppLovinQualityServiceSetup-ios.rb

SDK Keyを追加

File > Project Settings > Infoを選択します。Custom iOS Propertiesの行の一つをクリックし、+をクリックして新しい行を追加します。 新しい行のキーを AppLovinSdkKey に設定し、値をSDK Keyに設定します。

SDK KeyはAppLovinダッシュボードのAccount > General > Keys のセクションにてご確認ください。

MAX SDKを初期化

SDKの初期化構成を作成する

SDKを初期化する前に、アプリデリゲートのapplication:applicationDidFinishLaunching:メソッドで、SDKの初期化構成オブジェクトを作成します。

この設定オブジェクトでは、SDKが初期化時に使用するプロパティを設定できます。 これらの初期化プロパティは不変ですが、ALSdkSettings はアプリのライフサイクル中に変更可能なプロパティを含んでいます。

// Create the initialization configuration
ALSdkInitializationConfiguration *initConfig = [ALSdkInitializationConfiguration configurationWithSdkKey: @"«SDK-key»" builderBlock:^(ALSdkInitializationConfigurationBuilder *builder) {
builder.mediationProvider = ALMediationProviderMAX;
// Perform any additional configuration/setting changes
}];

SDK KeyはAppLovinダッシュボードのAccount > General > Keys のセクションにてご確認ください。

MAX SDKを初期化

初期化構成オブジェクトを使用してAppLovin SDKを初期化します。 これをスタートアップ時に行ってください。 これにより、SDKがメディエーションネットワークの広告をキャッシュする時間を最大化し、ユーザー体験の向上につながります。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create the initialization configuration
ALSdkInitializationConfiguration *initConfig = [ALSdkInitializationConfiguration configurationWithSdkKey: @"«SDK-key»" builderBlock:^(ALSdkInitializationConfigurationBuilder *builder) {
builder.mediationProvider = ALMediationProviderMAX;
}];
// Initialize the SDK with the configuration
[[ALSdk shared] initializeWithConfiguration: initConfig completionHandler:^(ALSdkConfiguration *sdkConfig) {
// Start loading ads
}];

以下は実装の例です。

// Create the initialization configuration
ALSdkInitializationConfiguration *initConfig = [ALSdkInitializationConfiguration configurationWithSdkKey: @"«SDK-key»" builderBlock:^(ALSdkInitializationConfigurationBuilder *builder) {
builder.mediationProvider = ALMediationProviderMAX;
builder.segmentCollection = [MASegmentCollection segmentCollectionWithBuilderBlock:^(MASegmentCollectionBuilder *builder) {
[builder addSegment: [[MASegment alloc] initWithKey: @(849) values: @[@(1), @(3)]]];
}];
}];
// Configure the SDK settings if needed before or after SDK initialization.
ALSdkSettings *settings = [ALSdk shared].settings;
settings.userIdentifier = @"«user-ID»";
[settings setExtraParameterForKey: @"uid2_token" value: @"«token-value»"];
// Note: you may also set these values in your Info.plist
settings.termsAndPrivacyPolicyFlowSettings.enabled = YES;
settings.termsAndPrivacyPolicyFlowSettings.termsOfServiceURL = [NSURL URLWithString: @"«https://your-company-name.com/terms-of-service»"];
settings.termsAndPrivacyPolicyFlowSettings.privacyPolicyURL = [NSURL URLWithString: @"«https://your-company-name.com/privacy-policy»"];
// Initialize the SDK with the configuration
[[ALSdk shared] initializeWithConfiguration: initConfig completionHandler:^(ALSdkConfiguration *sdkConfig) {
// Start loading ads
}];

SKAdNetwork

連携手順については、SKAdNetworkのドキュメントをご覧ください。

インタースティシャル広告

インタースティシャルをロード

インタースティシャル広告をロードするには、広告ユニットでMAInterstitialAd をインスタンス化し、loadAd() オブジェクトを呼び出します。 広告の準備が完了した際やその他の広告イベントを通知できるように、MAAdDelegate を実装してください。

#import "ExampleViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>
@interface ExampleViewController()<MAAdDelegate>
@property (nonatomic, strong) MAInterstitialAd *interstitialAd;
@property (nonatomic, assign) NSInteger retryAttempt;
@end
@implementation ExampleViewController
- (void)createInterstitialAd
{
self.interstitialAd = [[MAInterstitialAd alloc] initWithAdUnitIdentifier: @"«ad-unit-ID»"];
self.interstitialAd.delegate = self;
// Load the first ad
[self.interstitialAd loadAd];
}
#pragma mark - MAAdDelegate Protocol
- (void)didLoadAd:(MAAd *)ad
{
// Interstitial ad is ready to be shown. '[self.interstitialAd isReady]' will now return 'YES'
// Reset retry attempt
self.retryAttempt = 0;
}
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error
{
// Interstitial ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
self.retryAttempt++;
NSInteger delaySec = pow(2, MIN(6, self.retryAttempt));
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self.interstitialAd loadAd];
});
}
- (void)didDisplayAd:(MAAd *)ad {}
- (void)didClickAd:(MAAd *)ad {}
- (void)didHideAd:(MAAd *)ad
{
// Interstitial ad is hidden. Pre-load the next ad
[self.interstitialAd loadAd];
}
- (void)didFailToDisplayAd:(MAAd *)ad withError:(MAError *)error
{
// Interstitial ad failed to display. AppLovin recommends that you load the next ad
[self.interstitialAd loadAd];
}
@end

インタースティシャル広告を表示

インタースティシャル広告を表示するには、上記で作成したMAInterstitialAdオブジェクトに対してshowAd()を呼び出します。

if ( [self.interstitialAd isReady] )
{
[self.interstitialAd showAd];
}

リワード広告

リワード広告をロード

リワード広告をロードするには、リワード広告ユニットで MARewardedAd オブジェクトを取得し、それに対して loadAd() を呼び出します。 広告が準備完了した際やその他の広告イベントを通知できるように、MARewardedAdDelegate を実装してください。

#import "ExampleViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>
@interface ExampleViewController()<MARewardedAdDelegate>
@property (nonatomic, strong) MARewardedAd *rewardedAd;
@property (nonatomic, assign) NSInteger retryAttempt;
@end
@implementation ExampleViewController
- (void)createRewardedAd
{
self.rewardedAd = [MARewardedAd sharedWithAdUnitIdentifier: @"«ad-unit-ID»"];
self.rewardedAd.delegate = self;
// Load the first ad
[self.rewardedAd loadAd];
}
#pragma mark - MAAdDelegate Protocol
- (void)didLoadAd:(MAAd *)ad
{
// Rewarded ad is ready to be shown. '[self.rewardedAd isReady]' will now return 'YES'
// Reset retry attempt
self.retryAttempt = 0;
}
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error
{
// Rewarded ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
self.retryAttempt++;
NSInteger delaySec = pow(2, MIN(6, self.retryAttempt));
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self.rewardedAd loadAd];
});
}
- (void)didDisplayAd:(MAAd *)ad {}
- (void)didClickAd:(MAAd *)ad {}
- (void)didHideAd:(MAAd *)ad
{
// Rewarded ad is hidden. Pre-load the next ad
[self.rewardedAd loadAd];
}
- (void)didFailToDisplayAd:(MAAd *)ad withError:(MAError *)error
{
// Rewarded ad failed to display. AppLovin recommends that you load the next ad
[self.rewardedAd loadAd];
}
#pragma mark - MARewardedAdDelegate Protocol
- (void)didRewardUserForAd:(MAAd *)ad withReward:(MAReward *)reward
{
// Rewarded ad was displayed and user should receive the reward
}
@end

リワード広告を表示

リワード広告を表示するには、上記で作成した MARewardedAd オブジェクトに対して showAd() を呼び出します。

if ( [self.rewardedAd isReady] )
{
[self.rewardedAd showAd];
}

バナーおよび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 or background color for banner 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 { /* use this for impression tracking */ }
- (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を非表示にするには、次を呼び出します。

adView.hidden = YES;
[adView stopAutoRefresh];

バナーまたはMRECを非表示にするには、次を呼び出します。

adView.hidden = NO;
[adView startAutoRefresh];

メディエーションネットワークの準備

連携するアドネットワークを選択します。 その後、以下の手順に従ってください。

MAX メディエーションネットワークの手動ダウンロード