Back to top

Import and Initialize SDK

Last Updated on: 21 Jul, 2022

BEFORE YOU START

Meson supports iOS version 10 and above.

The download and use of the SDK are subject to the Meson SDK Licensing Terms. If you do not agree to these terms, do not download, access, or use the SDK, or the underlying services.

Add Meson SDK to the project

Meson supports both Cocoapods and manual download mechanisms to integrate our SDK.

CocoaPods

CocoaPods is a dependency manager for Objective-C and Swift; it automates and simplifies the SDK integration process. See the CocoaPods Guide on Getting Started and Using CocoaPods for more information.

To integrate the Meson SDK with CocoaPods, enter the following in your podfile:

pod 'MesonSDK' , '1.0.0-beta6'

Manual

Download Meson Prime SDK

After download, unzip it and add MesonSDK.xcframework into your Xcode Project.

Add Mediated SDK and Adaptor

CocoaPods

To add the mediated SDK adaptor and SDK with CocoaPods, select the networks and add the following dependencies to the pod file. See the list of supported networks and integration guides here.

  • Audience Network
  • InMobi
  • Vungle
  • Mintegral
  • Unity
  • Applovin
  • Ironsource
  • Google AdMob
  • Google Ad Manager
Real-time CPM
pod 'FBAudienceNetwork', '6.9.0'
pod 'MesonFANAdapter', '6.9.0.0-beta5'
Real-time CPM
pod 'InMobiSDK', '10.0.7'
pod 'MesonInMobiAdapter' , '10.0.7.0-beta6'
Real-time CPM
pod 'VungleSDK-iOS', '6.11.0'
pod 'MesonVungleAdapter', '6.11.0.0-beta6'
Real-time CPM
pod 'MintegralAdSDK', '7.1.7'
pod 'MesonMintegralAdapter', '7.1.7.0-beta6'
Predicted CPM
pod 'UnityAds', '4.2.1'
pod 'MesonUnityAdapter', '4.2.1.0-beta6'
Predicted CPM
pod 'AppLovinSDK', '11.4.2'
pod 'MesonApplovinAdapter', '11.4.2.1-beta6'
Fixed CPM
pod 'IronSourceSDK', '7.2.2.1'
pod 'MesonIronSourceAdapter', '7.2.2.0-beta6'
Fixed CPM
pod 'Google-Mobile-Ads-SDK', '9.6.0'
pod 'MesonAdmobAdapter', '9.6.0.0-beta6'
Fixed CPM
pod 'Google-Mobile-Ads-SDK', '9.6.0'
pod 'MesonGAMAdapter', '9.6.0.0-beta6'

Manual

Download the mediation adaptors. Copy the .xcframework files to the XCode project.

Download the mediated SDK. Copy the .xcframework/lib files to the XCode project.

See the list of supported networks and integration guides here.

  Name Bid Type Formats  
Audience Network Real-time CPM
Adaptor | SDK
Vungle Real-time CPM
Adaptor | SDK
InMobi Real-time CPM
Adaptor | SDK
Mintegral Real-time CPM
Adaptor | SDK
Unity Ads Predicted CPM
Adaptor | SDK
Applovin Predicted CPM
Adaptor | SDK
ironSource Fixed CPM
Adaptor | SDK
AdMob Fixed CPM
Adaptor | SDK
Google Ad Manager Fixed CPM
Adaptor | SDK

Integrating Apps in Objective C

If your project is in Objective C:

  • Add an empty swift file in the project to fetch all the swift-related system settings. For more information please follow this article here.
  • Add the following linker flags to the build settings at, Target > Build Settings > Linking > Other Linker Flags: -ObjC

Update the Property List File

To ensure uninterrupted support for ad delivery across all SDK-less Networks/Demand Partners, it's important to make the following changes in your info.plist:

  • Add in dictionary called 'NSAppTransportSecurity'. Make sure you add this dictionary to the 'Top-Level Key'
  • Inside this dictionary, add a Boolean with the key 'NSAllowsArbitraryLoads' and set it to YES

INFO

Make sure that your info.plist does not contain any other exceptions besides 'NSAllowsArbitraryLoad', as this might create a conflict. Find more information on ATS here.

Initialize the SDK

Initialize the SDK by calling Meson.initialize(MesonSDKConfiguration configuration) method. The SDK must be initialized successfully before carrying out any other operations.

During initialization, the SDK will:

  • Fetch the app configurations from the server
  • Set the GDPR consent settings for the app
  • Set the 'Do Not Sell' data restrictions within a US privacy jurisdiction (such as CCPA)
  • Initialize mediated SDKs

Initialize the SDK once per app lifecycle using the MesonSdkConfiguration object. The listener object is optional.

Swift

let gdprConsent = [MesonConstant.MESON_GDPR_CONSENT_GDPR_APPLIES : "0",
            MesonConstant. MESON_GDPR_CONSENT_AVAILABLE : "true",
            MesonConstant.MESON_GDPR_CONSENT_IAB : "<IAB String v1 or v2>" ]

//Initialize Meson SDK

Meson.initialize(sdkConfiguration: MesonSdkConfiguration(appId: "<APP_ID>", consent: gdprConsent)) { error in
      if let error = error as NSError?, let initializeError = MesonInitializationError.init(rawValue: error.code) {
        switch initializeError {
        case .configFetchFailed:
            print("")
        case .serverUnreachable:
            print("")
        case .invalidAppId:
            print("")
        case .osNotSupported:
            print("")
        @unknown default:
            print("")
        }
    }
    print("Meson SDK initialized successfully")
}

Objective-C

NSDictionary *gdprConsent = @{MesonConstant.MESON_GDPR_CONSENT_GDPR_APPLIES: @"0",
                            MesonConstant.MESON_GDPR_CONSENT_AVAILABLE: @"true",
                            MesonConstant.MESON_GDPR_CONSENT_IAB: @"IAB String v1 or v2" };

MesonSdkConfiguration *sdkConfiguration = [[MesonSdkConfiguration alloc] initWithAppId:@"<APP_ID>" consent:gdprConsent];

void (^completionBlock)(NSError*) = ^( NSError* _Nullable  error) {
    if (error) {
        NSLog(@"%@", error.description);
    } else {
        NSLog(@"SDK initialize successfully");
    }
};

[Meson initializeWithSdkConfiguration:sdkConfiguration completion:completionBlock];

Restricted Data Processing

To help publishers comply with the California Consumer Privacy Act (CCPA), the Meson SDK allows publishers to use either of the following parameters to enable restricted data processing (RDP). The parameter can be set at an ad request level utilizing the following parameters:

rdp: Set this to 1 for signaling restricted data processing.

us_privacy: Follow the IAB specification for signaling restricted data processing.

Swift

// You can notify Meson that restricted data processing is enabled using either of the following parameters.
let extras =  [
    "rdp": false,
    "iab_usprivacy_string": "1YNN"
] as [String : Any]

Meson.setExtras(extras)

Objective-C

// You can notify Meson that restricted data processing is enabled using either of the following parameters.
NSDictionary *extras = @{
    @"rdp": @(FALSE),
    @"iab_usprivacy_string": @("1YNN"),
};

[Meson setExtras:extras];

Add User Data

INFO

To use cohorts in Meson UI, this is where you will need to set PPID unique to a user

To use segments or experiments in Meson UI, this is where you will need to send the segments or experiments.

This is optional. In case you want to send us any information about the user, please do as follows:

To set user data, follow:

Swift

//Set Extras
let extras =  [
    "age": age,
    "gender": Gender.Male.rawValue,
    "interests":"<interests>",
    "language": "<language>",
    "customIds": [ ["idtype":"PPID", "value": "adada134412y1876dad"],
                    ["idtype":"IDL", "value": "mpqdan134412y1876dad"]],
    "segments": ["s1","s2","s3"],
    "experiments": ["e1","e2","e3"]] as [String : Any]

Meson.setExtras(extras)

//Set Location
Meson.setLocation(<#CLLocation>)

Objective-C

NSDictionary *extras = @{
    @"age": @(18),
    @"gender": @(GenderMale),
    @"interests":@"<interests>",
    @"language": @"<language>",
    @"customIds": @[ @{@"idtype":@"IMEI", @"value": @"adada134412y1876dad"},
    @{@"idtype":@"CAID", @"value": @"mpqdan134412y1876dad"}],
    @"segments": @[@"s1",@"s2",@"s3"],
    @"experiments": @[@"e1",@"e2",@"e3"]};

[Meson setExtras:extras];

//Set Location
[Meson setLocation:<#CLLocation>];

To get or reset user data, follow:

Swift

//Getters
Meson.getExtras() //gets the extra values set in SetExtras
Meson.getSDKVersion() //gets the SDK version

//Clears Extras, location
Meson.clearUserInfo()

Objective-C

//Getters
[Meson getSDKVersion];
[Meson getExtras];

//Clears extras, location
[Meson cleanUserInfo];

Configure Logging

When logging is set to DEBUG, SDK will print key logs to the console that provide useful information about the initialization and bid request lifecycle.

Swift

Meson.setLogLevel(.debug)

Objective-C

[Meson setLogLevel:LogLevelDebug];