AppLovin iOS SDK 12.3.1 introduces a new set of SDK initialization APIs.
This deprecates the old way of initializing the SDK.
The new APIs provide a straightforward and organized way to initialize the SDK.
They also address issues with the old APIs.
Note
You must set your SDK Key in the ALSdkInitializationConfiguration
initializer.
If your Info.plist
contains an entry for “ALSdkKey
”, you must remove it.
You can find your SDK key in the Account > General > Keys section of the AppLovin dashboard.
Create the SDK Initialization Configuration
Before you initialize the SDK, create an initialization configuration object for the SDK in your app delegate’s application:applicationDidFinishLaunching:
method.
This configuration object allows you to configure the properties that the SDK will initialize with.
These initialization properties are immutable, with the exception of ALSdkSettings
which contains mutable properties that can be changed during the lifetime of the app.
// 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
Initialize the SDK
Initialize the AppLovin SDK with the initialization configuration object.
Do this at startup.
This maximizes the time the SDK can take to cache mediated network ads, which results in a better user experience.
- ( 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) {
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
Example
Below is a sample integration that calls the new APIs.
You can also refer to this commit in the demo app, which demonstrates its migration to the new API.
// 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) {
// 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