Import and Initialize SDK

Last Updated on: 15 Nov, 2022

BEFORE YOU START

  • Supported iOS version 10 and above.
  • Supported Xcode version 13.2.1 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.

MESON MEDIATION DEMO APP

You can download the Integration Demo application for a better understanding. It demonstrates how you can integrate Meson Mediation into your app.

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-beta7'

Manual

Download Meson Prime SDK

After downloading, 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. For more information on the supported networks and integration, see Network Guides.

 

 

Use the following command to update the repository:

pod install --repo-update

Manual

To download the mediated SDKs and the supported adaptor, click the link provided for each network. For more information on the supported networks and integration, see Network Guides.

Network Bid Type Formats  
Real-time CPM
Adaptor | SDK
Real-time CPM
Adaptor | SDK
Real-time CPM
Adaptor | SDK
Real-time CPM
Adaptor | SDK
Predicted CPM
Adaptor | SDK
Predicted CPM
Adaptor | SDK
Fixed CPM
Adaptor | SDK
Fixed CPM
Adaptor | SDK
Fixed CPM
Adaptor | SDK

Integrating Apps in Objective C

Add the following linker flags to the build settings at, Target > Build Settings > Linking > Other Linker Flags: -ObjC

Important Prerequisites

App Transport Security (ATS)

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

<key>NSAppTransportSecurity</key> 
<dict>      
        <key>NSAllowsArbitraryLoads</key>     
        <true/> 
</dict>

INFO

Ensure that your info.plist does not contain exceptions besides 'NSAllowsArbitraryLoad', as this might create a conflict. For more information on ATS, see NSAppTransportSecurity.

iOS 12 WiFi Settings

Apple has introduced privacy settings to access WiFi details from iOS 12 onwards. To boost monetization and relevant user experience, we encourage sharing WiFi details for targeted advertising.

  1. Enable ‘Access WiFi Information’ on your App ID.

  2. Enable ‘Access WiFi Information’ for your target app from XCode capabilities.

  3. Ensure WiFi Access is added to your App.entitlements file.

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
  • Initialize mediated SDKs

Initialize the SDK once per app lifecycle using the MesonSdkConfiguration object.

MesonSdkConfiguration

Swift

import UIKit 
import MesonSDK 
 
@main 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 
        // Override point for customization after application launch.          
        // Setting Log level 
        Meson.setLogLevel(.debug) 

        initializeMesonSDK() 
       
        return true 
    } 

    private func initializeMesonSDK() { 

        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>"] 
         
#warning("Please enter you appId") 
        let config = MesonSdkConfiguration(appId: "appId", consent: gdprConsent) 
        Meson.initialize(sdkConfiguration: config) { error in 
            if let error = error as NSError?, let initializeError = MesonInitializationError.init(rawValue: error.code) { 
                print("MesonSDK initialization error \(initializeError)") 
            } 
            print("Meson\(Meson.getSDKVersion()) SDK initialized successfully") 
        } 
    } 

}

Objective-C

#import "AppDelegate.h" 
@import MesonSDK; 
 
@interface AppDelegate ()  
@end 
  

@implementation AppDelegate 
 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Override point for customization after application launch. 
    
    // Setting Log level 
    [Meson setLogLevel:LogLevelDebug]; 

    [self initializeMesonSDK]; 
     
    return YES; 
} 

  
- (void)initializeMesonSDK { 
    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" }; 

 
     #warning("Please enter you appId") 
    MesonSdkConfiguration *sdkConfiguration = [[MesonSdkConfiguration alloc] initWithAppId:@"appId" consent:gdprConsent]; 

 
     void (^completionBlock)(NSError*) = ^( NSError* _Nullable  error) { 
        if (error) { 
            NSLog(@"MesonSDK initialization error %@", error.description); 
        } else { 
            NSLog(@"Meson %@ SDK initialized successfully",[Meson getSDKVersion]); 
        } 
    }; 

  
    [Meson initializeWithSdkConfiguration:sdkConfiguration completion:completionBlock]; 
} 
@end

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

// Setting Log level 
Meson.setLogLevel(.debug)

Objective-C

// Setting Log level 
[Meson setLogLevel:LogLevelDebug];