Initialize the MoPub SDK for iOS

The MoPub 5.0 SDK introduces a new API for initialization called [[MoPub sharedInstance] initializeSdkWithConfiguration:sdkConfig completion:nil]. This API is required for a number of new functionalities, including:

v5.0.0 to v5.4.1:

  • GDPR consent mechanisms
  • Rewarded video pre-initialization

v5.5.0 and above:

  • GDPR consent mechanisms
  • Mediation SDKs initialization
  • Logging
  • Advanced Bidding
  • Legitimate Interest

Note: If you have been using [[MoPub sharedInstance] initializeRewardedVideoWithGlobalMediationSettings], it is now part of the new initialization, so make sure to switch to the new API.

Instructions

You only need to initialize once using any valid ad unit ID from your app. Ad requests should only be made once the SDK initialization has completed.

  1. In your app’s didFinishLaunchingWithOptions:, instantiate a MPMoPubConfiguration with any valid ad unit ID from your app, your mediation settings (optional), (optional) log level, (optional) map of configurations for networks, and (optional) a list of adapter configuration class names to initialize.
  2. Call initializeSdkWithConfiguration: and pass in your MPMoPubConfiguration instance.

Network SDK Initialization

SDK initialization will automatically attempt to initialize all known networks. However, publishers will be given the option to specify additional networks via the SDK configuration object as shown in the example below. globalMediationSettings API enable you to pass in third-party network specific settings. Note you can use .mediatedNetworkConfigurations() to pass network configurations required for pre-initialization. Otherwise expect your first attempt to pre-initialize mediated networks to fail because no network data is cached at this point. All your subsequent attempts to pre-initialize should succeed for the duration of the app’s life.

Logging Information

The MoPub 5.5.0 SDK has enhanced logging formats to include more detailed information such as adapter version, SDK version, and ad life cycle events and operations. You can enable these debug logs by setting MPLogLevel to MPLogLevelDebug during initialization.

Legitimate Interest

The MoPub SDK 5.5.0 now enables mediated networks to collect your user’s personal data based on legitimate interest basis when publishers opt-in. For more details read here. You can enable the legitimate interest flag using the API .allowLegitimateInterest during initialization.

Initializing custom ad networks not listed on Supported Mediation Partners

In order to initialize the custom network SDKs, follow the steps below:

  • Subclass MPBaseAdapterConfiguration. For instructions for how to implement that interface, reference this guide.
  • Set the network configuration options for a given mediated network class name by using the dictionary mediatedNetworkConfigurations. Refer to the example below.

Example

MPMoPubConfiguration *sdkConfig = [[MPMoPubConfiguration alloc] initWithAdUnitIdForAppInitialization:@"AD_UNIT_ID"];

sdkConfig.globalMediationSettings = @[];
sdkConfig.loggingLevel = MPLogLevelInfo;
sdkConfig.allowLegitimateInterest(BOOL);
sdkConfig.allowLegitimateInterest(BOOL);
sdkConfig.additionalNetworks(NSArray of class names);
sdkConfig.mediatedNetworkConfigurations(NSMutableDictionary of network configuration);

[[MoPub sharedInstance] initializeSdkWithConfiguration:sdkConfig completion:^{
        NSLog(@"SDK initialization complete");
        // SDK initialization complete. Ready to make ad requests.
    }];

Last updated April 01, 2019

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2019 MoPub (a division of Twitter, Inc.)