要接收版本更新,请订阅 AppLovin-MAX-SDK-iOS GitHub 库。
已下载的 ZIP 文件包含 AppLovinSDK.xcframework 文件。
要将 SDK 添加到您的应用程序,请将 AppLovinSDK.xcframework 文件拖拽至您的 Xcode 项目中,并确保 Xcode 项目目标设置里的 Frameworks, Libraries, and Embedded Content 部分中包含 AppLovinSDK.xcframework。
您必须添加 -ObjC 标记才能编译 AppLovin SDK。
要启用 -ObjC 标记,请选择 File > Project Settings,前往 Build Settings,搜索 Other Linker Flags,然后点击 + 符号以添加 -ObjC。
请在您的项目中关联下列框架:
要启用 MAX Ad Review 服务,再下载AppLovinQualityServiceSetup-ios.rb并将它移入您的项目文件夹中。
打开终端窗口,将 cd 进入到您的项目目录中,然后运行:
ruby AppLovinQualityServiceSetup-ios.rb
选择 File > Project Settings > Info。
点击 Custom iOS Properties 中的一行,然后点击 + 符号以添加新的行。
将新一行的键设置为 AppLovinSdkKey,并将值设为您的 SDK Key。
您可以在 AppLovin 控制面板的 Account > General > Keys 部分找到 SDK Key。
在初始化 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
}];
// Create the initialization configuration
let initConfig = ALSdkInitializationConfiguration(sdkKey: "«SDK-key»") { builder in
builder.mediationProvider = ALMediationProviderMAX
// Perform any additional configuration/setting changes
}
您可以在 AppLovin 控制面板的 Account > General > Keys 部分找到 SDK Key。
请在应用启动时,使用初始化配置对象来初始化 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 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
}];
// Create the initialization configuration
let 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().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.isEnabled = true
settings.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 configuration
ALSdk.shared().initialize(with: initConfig) { sdkConfig in
// Start loading ads
}
请参阅 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()
}
要加载广告,请使用您的广告单元创建一个 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 = true
adView.stopAutoRefresh()
要显示横幅或 MREC,请进行如下调用:
adView.hidden = NO;
[adView startAutoRefresh];
adView.isHidden = false
adView.startAutoRefresh()
选择要集成的广告平台, 然后按照以下说明操作。
从 Pangle iOS 适配器 4.9.1.0.0 版本开始,中国大陆地区已下架 Pangle。 要通过中国大陆流量变现,请设置 CSJ 平台并添加 CSJ 适配器。对于中国大陆以外的全球流量,可以继续使用 Pangle 进行变现。
要支持 iOS 12.2 以下版本的 Swift,请按照下列步骤操作:

window 属性请勿移除应用委托文件的 window 属性。
否则,InMobi 的 SDK 可能会崩溃。
@property (nonatomic, strong) UIWindow *window;
var window: UIWindow?
如果您不想启用限制数据使用 (LDU) 模式,请向 SetDataProcessingOptions() 传递一个空数组:
#import <FBAudienceNetwork/FBAudienceNetwork.h>
⋮
[FBAdSettings setDataProcessingOptions: @[]];
⋮
// Initialize MAX SDK
import FBAudienceNetwork
⋮
FBAdSettings.setDataProcessingOptions([])
⋮
// Initialize MAX SDK
要为用户启用 LDU 并指定用户地理位置,请按如下方式调用 SetDataProcessingOptions():
#import <FBAudienceNetwork/FBAudienceNetwork.h>
⋮
[FBAdSettings setDataProcessingOptions: @[@"LDU"] country: «country» state: «state»];
⋮
// Initialize MAX SDK
import FBAudienceNetwork
⋮
FBAdSettings.setDataProcessingOptions(["LDU"], country: «country», state: «state»)
⋮
// Initialize MAX SDK
如果您使用 Google UMP 作为 CMP,则可以判断用户是否已向 Meta 授予许可。 为此,请使用如下代码:
NSNumber *hasMetaConsent = [ALPrivacySettings additionalConsentStatusForIdentifier: 89];
if ( hasMetaConsent )
{
BOOL consentGiven = hasMetaConsent.boolValue;
// Set Meta Data Processing Options accordingly.
}
else
{
// AC String is not available on disk. Please check for consent status after the user completes the CMP flow.
}
let hasMetaConsent = ALPrivacySetting.additionalConsentStatus(forIdentifier: 89)
if let consentGiven = hasMetaConsent?.boolValue
{
// Set Meta Data Processing Options accordingly.
}
else
{
// AC String is not available on disk. Please check for consent status after the user completes the CMP flow.
}
要了解如何在加利福尼亚州启用 Meta Audience Network 的 “Limited Data Use” (限制数据使用) 标记,请参阅 Meta 开发者文档。
Audience Network SDK 6.2.1 于 2021 年 1 月 11 日发布。 此版本包含以下重要要求:
setAdvertiserTrackingEnabled 标记。
Meta 会据此判断能否使用这些数据来投放个性化广告。Info.plist,以便广告主可以监测广告 Campaign 的成效。
请参阅 SKAdNetwork 文档 了解集成说明。[sdk initializeSdkWithCompletionHandler:^(ALSdkConfiguration *sdkConfiguration)
{
if ( @available(iOS 14.5, *) )
{
// Note that App transparency tracking authorization can be checked via `sdkConfiguration.appTrackingTransparencyStatus`
// 1. Set Meta ATE flag here, THEN
}
// 2. Load ads
}];
sdk.initializeSdk { (sdkConfiguration: ALSdkConfiguration) in
if #available(iOS 14.5, *)
{
// Note that App transparency tracking authorization can be checked via `sdkConfiguration.appTrackingTransparencyStatus`
// 1. Set Meta ATE flag here, THEN
}
// 2. Load ads
}
使用 Google AdSense、AdManager 或 AdMob 的开发者和发行商必须使用经过 Google 认证的许可管理平台 (CMP)。 要向欧洲经济区 (EEA) 或英国的用户投放广告,您的 CMP 必须集成 IAB 的透明度和许可框架。 请参阅 Privacy: “TCF v2 Consent” 了解更多信息。
在应用的 Info.plist 中添加 GADApplicationIdentifier 键,
其字符串值为 Google 竞价和 Google AdMob / Google Ad Manager 应用 ID。

Amazon Publisher Services SDK 需要在 MAX SDK 之外进行初始化:
[[DTBAds sharedInstance] setAppKey: appId];
[DTBAds sharedInstance].mraidCustomVersions = @[@"1.0", @"2.0", @"3.0"];
[DTBAds sharedInstance].mraidPolicy = CUSTOM_MRAID;
请使用最新版本的 Amazon Publisher Services 适配器,避免报告差异。
要在 MAX 中集成 Amazon 广告,则必须先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse 或 DTBAdErrorInfo 传递至 MAAdView 实例。
您可以通过调用 -[MAAdView setLocalExtraParameterForKey:value:] 来完成此操作。
对于自动刷新横幅广告,只需加载广告一次。
@interface ExampleViewController ()<DTBAdCallback>
⋮
@end
@implementation ExampleViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *amazonAdSlotId;
MAAdFormat *adFormat;
if ( UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad )
{
amazonAdSlotId = @"«Amazon-leader-slot-ID»";
adFormat = MAAdFormat.leader;
}
else
{
amazonAdSlotId = @"«Amazon-banner-slot-ID»";
adFormat = MAAdFormat.banner;
}
CGSize rawSize = adFormat.size;
DTBAdSize *size = [[DTBAdSize alloc] initBannerAdSizeWithWidth: rawSize.width
height: rawSize.height
andSlotUUID: amazonAdSlotId];
DTBAdNetworkInfo *adNetworkInfo = [[DTBAdNetworkInfo alloc] initWithNetworkName: DTBADNETWORK_MAX];
DTBAdLoader *adLoader = [[DTBAdLoader alloc] initWithAdNetworkInfo: adNetworkInfo];
[adLoader setAdSizes: @[size]];
[adLoader loadAd: self];
}
- (void)onSuccess:(DTBAdResponse *)adResponse
{
// 'adView' is your instance of MAAdView
[self.adView setLocalExtraParameterForKey: @"amazon_ad_response" value: adResponse];
[self.adView loadAd];
}
- (void)onFailure:(DTBAdError)error dtbAdErrorInfo:(DTBAdErrorInfo *)errorInfo
{
// 'adView' is your instance of MAAdView
[self.adView setLocalExtraParameterForKey: @"amazon_ad_error" value: errorInfo];
[self.adView loadAd];
}
@end
import AppLovinSDK
import DTBiOSSDK
class ExampleViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
let amazonAdSlotId: String
let adFormat: MAAdFormat
if UIDevice.current.userInterfaceIdiom == .pad
{
amazonAdSlotId = "«Amazon-leader-slot-ID»"
adFormat = MAAdFormat.leader
}
else
{
amazonAdSlotId = "«Amazon-banner-slot-ID»"
adFormat = MAAdFormat.banner
}
let rawSize = adFormat.size
let size = DTBAdSize(bannerAdSizeWithWidth: Int(rawSize.width),
height: Int(rawSize.height),
andSlotUUID: amazonAdSlotId)!
let adLoader = DTBAdLoader(adNetworkInfo: DTBAdNetworkInfo(networkName: DTBADNETWORK_MAX))
adLoader.setAdSizes([size])
adLoader.loadAd(self)
}
}
extension ExampleViewController: DTBAdCallback
{
func onSuccess(_ adResponse: DTBAdResponse!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_response", value: adResponse)
adView.loadAd()
}
func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_error", value:dtbAdErrorInfo)
adView.loadAd()
}
}
import AppLovinSDK
import DTBiOSSDK
struct ExampleSwiftUIWrapper: UIViewRepresentable
{
func makeUIView(context: Context) -> MAAdView
{
let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»")
adView.delegate = context.coordinator
let amazonAdSlotId: String
let adFormat: MAAdFormat
if UIDevice.current.userInterfaceIdiom == .pad
{
amazonAdSlotId = "«Amazon-leader-slot-ID»"
adFormat = MAAdFormat.leader
}
else
{
amazonAdSlotId = "«Amazon-banner-slot-ID»"
adFormat = MAAdFormat.banner
}
let rawSize = adFormat.size
let size = DTBAdSize(bannerAdSizeWithWidth: Int(rawSize.width),
height: Int(rawSize.height),
andSlotUUID: amazonAdSlotId)!
let adLoader = DTBAdLoader(adNetworkInfo: DTBAdNetworkInfo(networkName: DTBADNETWORK_MAX))
adLoader.setAdSizes([size])
adLoader.loadAd(adView)
return adView
}
}
extension ExampleSwiftUIWrapper
{
class Coordinator: DTBAdCallback
{
func onSuccess(_ adResponse: DTBAdResponse!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_response", value: adResponse)
adView.loadAd()
}
func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_error", value: dtbAdErrorInfo)
adView.loadAd()
}
}
}
@interface ExampleViewController ()<DTBAdCallback>
⋮
@end
@implementation ExampleViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *amazonAdSlotId = @"«Amazon-MREC-slot-ID»";
DTBAdNetworkInfo *adNetworkInfo = [[DTBAdNetworkInfo alloc] initWithNetworkName: DTBADNETWORK_MAX];
DTBAdLoader *adLoader = [[DTBAdLoader alloc] initWithAdNetworkInfo: adNetworkInfo];
[adLoader setAdSizes: [[DTBAdSize alloc] initBannerAdSizeWithWidth: 300
height: 250
andSlotUUID: amazonAdSlotId]];
[adLoader loadAd: self];
}
- (void)onSuccess:(DTBAdResponse *)adResponse
{
// 'adView' is your instance of MAAdView
[self.adView setLocalExtraParameterForKey: @"amazon_ad_response" value: adResponse];
[self.adView loadAd];
}
- (void)onFailure:(DTBAdError)error dtbAdErrorInfo:(DTBAdErrorInfo *)errorInfo
{
// 'adView' is your instance of MAAdView
[self.adView setLocalExtraParameterForKey: @"amazon_ad_error" value: errorInfo];
[self.adView loadAd];
}
@end
import AppLovinSDK
import DTBiOSSDK
class ExampleViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
let amazonAdSlotId: String = "«Amazon-MREC-slot-ID»"
let adLoader = DTBAdLoader(adNetworkInfo: DTBAdNetworkInfo(networkName: DTBADNETWORK_MAX))
adLoader.setAdSizes([DTBAdSize(bannerAdSizeWithWidth: 300,
height: 250,
andSlotUUID: amazonAdSlotId)!])
adLoader.loadAd(self)
}
}
extension ExampleViewController: DTBAdCallback
{
func onSuccess(_ adResponse: DTBAdResponse!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_response", value: adResponse)
adView.loadAd()
}
func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_error", value:dtbAdErrorInfo)
adView.loadAd()
}
}
import AppLovinSDK
import DTBiOSSDK
struct ExampleSwiftUIWrapper: UIViewRepresentable
{
func makeUIView(context: Context) -> MAAdView
{
let adView = MAAdView(adUnitIdentifier: "«ad-unit-ID»", adFormat: MAAdFormat.mrec)
adView.delegate = context.coordinator
let amazonAdSlotId: String = "«Amazon-MREC-slot-ID»"
let adLoader = DTBAdLoader(adNetworkInfo: DTBAdNetworkInfo(networkName: DTBADNETWORK_MAX))
adLoader.setAdSizes([DTBAdSize(bannerAdSizeWithWidth: 300,
height: 250,
andSlotUUID: amazonAdSlotId)!])
adLoader.loadAd(adView)
return adView
}
}
extension ExampleSwiftUIWrapper
{
class Coordinator: DTBAdCallback
{
func onSuccess(_ adResponse: DTBAdResponse!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_response", value: adResponse)
adView.loadAd()
}
func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!)
{
// 'adView' is your instance of MAAdView
adView.setLocalExtraParameterForKey("amazon_ad_error", value: dtbAdErrorInfo)
adView.loadAd()
}
}
}
要集成 Amazon 插屏广告到 MAX,您必须先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse 或 DTBAdErrorInfo 传递至 MAInterstitialAd 实例。
您可以通过调用 -[MAInterstitialAd setLocalExtraParameterForKey:value:] 来完成此操作。
在每个会话中,您只能加载一次 Amazon DTBAdResponse 或 DTBAdErrorInfo 并将其发送到 MAInterstitialAd 实例。
#import <AppLovinSDK/AppLovinSDK.h>
#import <DTBiOSSDK/DTBiOSSDK.h>
@interface ExampleViewController ()<DTBAdCallback>
⋮
@end
@implementation ExampleViewController
static MAInterstitialAd *interstitialAd;
static BOOL isFirstLoad;
+ (void)initialize
{
[super initialize];
interstitialAd = [[MAInterstitialAd alloc] initWithAdUnitIdentifier: @"«MAX-inter-ad-unit-ID»"];
isFirstLoad = YES;
}
- (void)loadAd
{
// If first load - load ad from Amazon's SDK, then load ad for MAX
if ( isFirstLoad )
{
isFirstLoad = NO;
DTBAdNetworkInfo *adNetworkInfo = [[DTBAdNetworkInfo alloc] initWithNetworkName: DTBADNETWORK_MAX];
DTBAdLoader *adLoader = [[DTBAdLoader alloc] initWithAdNetworkInfo: adNetworkInfo];
[adLoader setAdSizes: @[
[[DTBAdSize alloc] initInterstitialAdSizeWithSlotUUID: @"«Amazon-inter-slot-ID»"]
]];
[adLoader loadAd: self];
}
else
{
[interstitialAd loadAd];
}
}
- (void)onSuccess:(DTBAdResponse *)adResponse
{
// 'interstitialAd' is your instance of MAInterstitialAd
[interstitialAd setLocalExtraParameterForKey: @"amazon_ad_response" value: adResponse];
[interstitialAd loadAd];
}
- (void)onFailure:(DTBAdError)error dtbAdErrorInfo:(DTBAdErrorInfo *)errorInfo
{
// 'interstitialAd' is your instance of MAInterstitialAd
[interstitialAd setLocalExtraParameterForKey: @"amazon_ad_error" value: errorInfo];
[interstitialAd loadAd];
}
@end
import AppLovinSDK
import DTBiOSSDK
class ExampleViewController: UIViewController
{
private static var interstitialAd = MAInterstitialAd(adUnitIdentifier: "«MAX-inter-ad-unit-ID»")
private static var isFirstLoad = true
func loadAd()
{
// If first load - load ad from Amazon's SDK, then load ad for MAX
if Self.isFirstLoad
{
Self.isFirstLoad = false
let adLoader = DTBAdLoader(adNetworkInfo: DTBAdNetworkInfo(networkName: DTBADNETWORK_MAX))
adLoader.setAdSizes([DTBAdSize(interstitialAdSizeWithSlotUUID: "«Amazon-inter-slot-ID»")!])
adLoader.loadAd(self)
}
else
{
Self.interstitialAd.load()
}
}
}
extension ExampleViewController: DTBAdCallback
{
func onSuccess(_ adResponse: DTBAdResponse!)
{
// 'interstitialAd' is your instance of MAInterstitialAd
Self.interstitialAd.setLocalExtraParameterForKey("amazon_ad_response", value: adResponse)
Self.interstitialAd.load()
}
func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!)
{
// 'interstitialAd' is your instance of MAInterstitialAd
Self.interstitialAd.setLocalExtraParameterForKey("amazon_ad_error", value: dtbAdErrorInfo)
Self.interstitialAd.load()
}
}
要集成 Amazon 插屏广告到 MAX,您必须先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse 或 DTBAdErrorInfo 传递至 MAInterstitialAd 实例。
您可以通过调用 -[MAInterstitialAd setLocalExtraParameterForKey:value:] 来完成此操作。
在每个会话中,您只能加载一次 Amazon DTBAdResponse 或 DTBAdErrorInfo 并将其发送到 MAInterstitialAd 实例。
#import <AppLovinSDK/AppLovinSDK.h>
#import <DTBiOSSDK/DTBiOSSDK.h>
@interface ExampleViewController ()<DTBAdCallback>
⋮
@end
@implementation ExampleViewController
static MAInterstitialAd *interstitialAd;
static BOOL isFirstLoad;
+ (void)initialize
{
[super initialize];
interstitialAd = [[MAInterstitialAd alloc] initWithAdUnitIdentifier: @"«MAX-inter-ad-unit-ID»"];
isFirstLoad = YES;
}
- (void)loadAd
{
// If first load - load ad from Amazon's SDK, then load ad for MAX
if ( isFirstLoad )
{
isFirstLoad = NO;
DTBAdNetworkInfo *adNetworkInfo = [[DTBAdNetworkInfo alloc] initWithNetworkName: DTBADNETWORK_MAX];
DTBAdLoader *adLoader = [[DTBAdLoader alloc] initWithAdNetworkInfo: adNetworkInfo];
// Switch video player width and height values(320, 480) depending on device orientation
[adLoader setAdSizes: @[
[[DTBAdSize alloc] initVideoAdSizeWithPlayerWidth: 320 height: 480 andSlotUUID:@"«Amazon-video-inter-slot-ID»"]
]];
[adLoader loadAd: self];
}
else
{
[interstitialAd loadAd];
}
}
- (void)onSuccess:(DTBAdResponse *)adResponse
{
// 'interstitialAd' is your instance of MAInterstitialAd
[interstitialAd setLocalExtraParameterForKey: @"amazon_ad_response" value: adResponse];
[interstitialAd loadAd];
}
- (void)onFailure:(DTBAdError)error dtbAdErrorInfo:(DTBAdErrorInfo *)errorInfo
{
// 'interstitialAd' is your instance of MAInterstitialAd
[interstitialAd setLocalExtraParameterForKey: @"amazon_ad_error" value: errorInfo];
[interstitialAd loadAd];
}
@end
import AppLovinSDK
import DTBiOSSDK
class ExampleViewController: UIViewController
{
private static var interstitialAd = MAInterstitialAd(adUnitIdentifier: "«MAX-inter-ad-unit-ID»")
private static var isFirstLoad = true
func loadAd()
{
// If first load - load ad from Amazon's SDK, then load ad for MAX
if Self.isFirstLoad
{
Self.isFirstLoad = false
let adLoader = DTBAdLoader(adNetworkInfo: DTBAdNetworkInfo(networkName: DTBADNETWORK_MAX))
// Switch video player width and height values(320, 480) depending on device orientation
adLoader.setAdSizes([DTBAdSize(videoAdSizeWithPlayerWidth: 320, height: 480, andSlotUUID: "«Amazon-video-inter-slot-ID»")!])
adLoader.loadAd(self)
}
else
{
Self.interstitialAd.load()
}
}
}
extension ExampleViewController: DTBAdCallback
{
func onSuccess(_ adResponse: DTBAdResponse!)
{
// 'interstitialAd' is your instance of MAInterstitialAd
Self.interstitialAd.setLocalExtraParameterForKey("amazon_ad_response", value: adResponse)
Self.interstitialAd.load()
}
func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!)
{
// 'interstitialAd' is your instance of MAInterstitialAd
Self.interstitialAd.setLocalExtraParameterForKey("amazon_ad_error", value: dtbAdErrorInfo)
Self.interstitialAd.load()
}
}
要将 Amazon 激励视频广告集成到 MAX,必须先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse 或 DTBAdErrorInfo 传递至 MARewardedAd 实例。
您可以通过调用 -[MARewardedAd setLocalExtraParameterForKey:value:] 来完成此操作。
您只能加载一次 Amazon DTBAdResponse 或 DTBAdErrorInfo 并将其发送到 MARewardedAd 实例。
#import <AppLovinSDK/AppLovinSDK.h>
#import <DTBiOSSDK/DTBiOSSDK.h>
@interface ExampleViewController ()<DTBAdCallback>
⋮
@end
@implementation ExampleViewController
static MARewardedAd *rewardedAd;
static BOOL isFirstLoad;
+ (void)initialize
{
[super initialize];
rewardedAd = [MARewardedAd sharedWithAdUnitIdentifier: @"«MAX-rewarded-ad-unit-ID»"];
isFirstLoad = YES;
}
- (void)loadAd
{
// If first load - load ad from Amazon's SDK, then load ad for MAX
if ( isFirstLoad )
{
isFirstLoad = NO;
DTBAdNetworkInfo *adNetworkInfo = [[DTBAdNetworkInfo alloc] initWithNetworkName: DTBADNETWORK_MAX];
DTBAdLoader *adLoader = [[DTBAdLoader alloc] initWithAdNetworkInfo: adNetworkInfo];
// Switch video player width and height values(320, 480) depending on device orientation
[adLoader setAdSizes: @[
[[DTBAdSize alloc] initVideoAdSizeWithPlayerWidth: 320 height: 480 andSlotUUID:@"«Amazon-video-rewarded-slot-ID»"]
]];
[adLoader loadAd: self];
}
else
{
[rewardedAd loadAd];
}
}
- (void)onSuccess:(DTBAdResponse *)adResponse
{
// 'rewardedAd' is your instance of MARewardedAd
[rewardedAd setLocalExtraParameterForKey: @"amazon_ad_response" value: adResponse];
[rewardedAd loadAd];
}
- (void)onFailure:(DTBAdError)error dtbAdErrorInfo:(DTBAdErrorInfo *)errorInfo
{
// 'rewardedAd' is your instance of MARewardedAd
[rewardedAd setLocalExtraParameterForKey: @"amazon_ad_error" value: errorInfo];
[rewardedAd loadAd];
}
@end
import AppLovinSDK
import DTBiOSSDK
class ExampleViewController: UIViewController
{
private static var rewardedAd = MARewardedAd.shared(withAdUnitIdentifier: "«MAX-rewarded-ad-unit-ID»")
private static var isFirstLoad = true
func loadAd()
{
// If first load - load ad from Amazon's SDK, then load ad for MAX
if Self.isFirstLoad
{
Self.isFirstLoad = false
let adLoader = DTBAdLoader(adNetworkInfo: DTBAdNetworkInfo(networkName: DTBADNETWORK_MAX))
// Switch video player width and height values(320, 480) depending on device orientation
adLoader.setAdSizes([DTBAdSize(videoAdSizeWithPlayerWidth: 320, height: 480, andSlotUUID: "«Amazon-video-rewarded-slot-ID»")!])
adLoader.loadAd(self)
}
else
{
Self.rewardedAd.load()
}
}
}
extension ExampleViewController: DTBAdCallback
{
func onSuccess(_ adResponse: DTBAdResponse!)
{
// 'rewardedAd' is your instance of MARewardedAd
Self.rewardedAd.setLocalExtraParameterForKey("amazon_ad_response", value: adResponse)
Self.rewardedAd.load()
}
func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!)
{
// 'rewardedAd' is your instance of MARewardedAd
Self.rewardedAd.setLocalExtraParameterForKey("amazon_ad_error", value: dtbAdErrorInfo)
Self.rewardedAd.load()
}
}
AppLovin 建议您为 Amazon SDK 启用测试模式, 这样您就会收到测试广告。 使用以下调用启用测试模式:
[[DTBAds sharedInstance] setLogLevel: DTBLogLevelAll];
[[DTBAds sharedInstance] setTestMode: YES];
DTBAds.sharedInstance().setLogLevel(DTBLogLevelAll)
DTBAds.sharedInstance().testMode = true
您可以过滤瀑布流,使其只包含 Amazon 广告。 为此,请在Mediation Debugger中选择Select Live Network,然后选择 Amazon 平台。
要禁用 App Transport Security (ATS),请将 NSAppTransportSecurity 添加至应用的 Info.plist。
然后添加 NSAllowsArbitraryLoads键并将其布尔值设置为 YES。
确保这是唯一的键。

请参阅 the SKAdNetwork documentation 了解集成说明。