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
をプロジェクトディレクトリに移動して以下を実行します。
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 configurationALSdkInitializationConfiguration *initConfig = [ALSdkInitializationConfiguration configurationWithSdkKey: @"«SDK-key»" builderBlock:^(ALSdkInitializationConfigurationBuilder *builder) {
builder.mediationProvider = ALMediationProviderMAX;
// Perform any additional configuration/setting changes}];
// Create the initialization configurationlet initConfig = ALSdkInitializationConfiguration(sdkKey: "«SDK-key»") { builder in
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 }]; ⋮
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool{ let initConfig = ALSdkInitializationConfiguration(sdkKey: "«SDK-key»") { builder in builder.mediationProvider = ALMediationProviderMAX }
// Initialize the SDK with the configuration ALSdk.shared().initialize(with: initConfig) { sdkConfig in // Start loading ads } ⋮
例
以下は実装の例です。
// Create the initialization configurationALSdkInitializationConfiguration *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.plistsettings.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}];
// Create the initialization configurationlet initConfig = ALSdkInitializationConfiguration(sdkKey: "«SDK-key»") { builder in builder.mediationProvider = ALMediationProviderMAX builder.segmentCollection = MASegmentCollection { segmentCollectionBuilder in segmentCollectionBuilder.add(MASegment(key: 849, values: [1, 3])) }}
// Configure the SDK settings if needed before or after SDK initialization.let settings = ALSdk.shared().settingssettings.userIdentifier = "«user-ID»"settings.setExtraParameterForKey("uid2_token", value: "«token-value»")
// Note: you may also set these values in your Info.plistsettings.termsAndPrivacyPolicyFlowSettings.isEnabled = truesettings.termsAndPrivacyPolicyFlowSettings.termsOfServiceURL = URL(string: "«https://your-company-name.com/terms-of-service»")settings.termsAndPrivacyPolicyFlowSettings.privacyPolicyURL = URL(string: "«https://your-company-name.com/privacy-policy»")
// Initialize the SDK with the configurationALSdk.shared().initialize(with: initConfig) { sdkConfig in // 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
class ExampleViewController: UIViewController, MAAdDelegate{ var interstitialAd: MAInterstitialAd! var retryAttempt = 0.0
func createInterstitialAd() { interstitialAd = MAInterstitialAd(adUnitIdentifier: "«ad-unit-ID»") interstitialAd.delegate = self
// Load the first ad interstitialAd.load() }
// MARK: MAAdDelegate Protocol
func didLoad(_ ad: MAAd) { // Interstitial ad is ready to be shown. 'interstitialAd.isReady' will now return 'true'
// Reset retry attempt retryAttempt = 0 }
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) { // Interstitial ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt += 1 let delaySec = pow(2.0, min(6.0, retryAttempt))
DispatchQueue.main.asyncAfter(deadline: .now() + delaySec) { self.interstitialAd.load() } }
func didDisplay(_ ad: MAAd) {}
func didClick(_ ad: MAAd) {}
func didHide(_ ad: MAAd) { // Interstitial ad is hidden. Pre-load the next ad interstitialAd.load() }
func didFail(toDisplay ad: MAAd, withError error: MAError) { // Interstitial ad failed to display. AppLovin recommends that you load the next ad interstitialAd.load() }}
インタースティシャル広告を表示
インタースティシャル広告を表示するには、上記で作成したMAInterstitialAd
オブジェクトに対してshowAd()
を呼び出します。
if ( [self.interstitialAd isReady] ){ [self.interstitialAd showAd];}
if interstitialAd.isReady{interstitialAd.show()}
リワード広告
リワード広告をロード
リワード広告をロードするには、リワード広告ユニットで 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
class ExampleViewController : UIViewController, MARewardedAdDelegate{ var rewardedAd: MARewardedAd! var retryAttempt = 0.0
func createRewardedAd() { rewardedAd = MARewardedAd.shared(withAdUnitIdentifier: "«ad-unit-ID»") rewardedAd.delegate = self
// Load the first ad rewardedAd.load() }
// MARK: MAAdDelegate Protocol
func didLoad(_ ad: MAAd) { // Rewarded ad is ready to be shown. '[self.rewardedAd isReady]' will now return 'YES'
// Reset retry attempt retryAttempt = 0 }
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) { // Rewarded ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt += 1 let delaySec = pow(2.0, min(6.0, retryAttempt))
DispatchQueue.main.asyncAfter(deadline: .now() + delaySec) { self.rewardedAd.load() } }
func didDisplay(_ ad: MAAd) {}
func didClick(_ ad: MAAd) {}
func didHide(_ ad: MAAd) { // Rewarded ad is hidden. Pre-load the next ad rewardedAd.load() }
func didFail(toDisplay ad: MAAd, withError error: MAError) { // Rewarded ad failed to display. AppLovin recommends that you load the next ad rewardedAd.load() }
// MARK: MARewardedAdDelegate Protocol
func didRewardUser(for ad: MAAd, with reward: MAReward) { // Rewarded ad was displayed and user should receive the reward }}
リワード広告を表示
リワード広告を表示するには、上記で作成した MARewardedAd
オブジェクトに対して showAd()
を呼び出します。
if ( [self.rewardedAd isReady] ){ [self.rewardedAd showAd];}
if rewardedAd.isReady{ rewardedAd.show()}
バナーおよび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
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: CGFloat = (UIDevice.current.userInterfaceIdiom == .pad) ? 90 : 50
// Stretch to the width of the screen for banners to be fully functional let width: CGFloat = UIScreen.main.bounds.width
adView.frame = CGRect(x: x, y: y, width: width, height: height)
// Set background or background color for banner 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) { /* 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 */ }}
#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»" adlanguage: 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 or 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 { /* 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
class ExampleViewController: UIViewController, MAAdViewAdDelegate{ var adView: MAAdView!
func createMRECAd { adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", adlanguage: MAAdFormat.mrec) adView.delegate = self
// MREC width and height are 300 and 250 respectively, on iPhone and iPad let height: CGFloat = 250 let width: CGFloat = 300
adView.frame = CGRect(x: x, y: y, width: width, height: height)
// Center the MREC adView.center.x = view.center.x
// Set background or 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) { /* 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 */ }}
バナーまたはMRECを非表示にするには、次を呼び出します。
adView.hidden = YES;[adView stopAutoRefresh];
adView.isHidden = trueadView.stopAutoRefresh()
バナーまたはMRECを非表示にするには、次を呼び出します。
adView.hidden = NO;[adView startAutoRefresh];
adView.isHidden = falseadView.startAutoRefresh()
メディエーションネットワークの準備
連携するアドネットワークを選択します。 その後、以下の手順に従ってください。