Import and Initialize SDK

Last Updated on: 18 Apr, 2024

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 to gain a better understanding. It demonstrates how you can integrate Meson Mediation into your app.

Add Meson SDK to Project

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

CocoaPods

For users of Xcode 15 and later versions, you must employ the most up-to-date release of 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-beta13'

Manual

Download Meson Prime SDK

After downloading, unzip it and add MesonSDK.xcframework to your Xcode Project.

Add Mediated SDK and Adapter

CocoaPods

To add the mediated SDK adapter 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.

 

 

If you are on the Amazon network, see Integrate Amazon SDK for more information.

Use the following command to update the repository:

pod install --repo-update

Manual

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

Network Bid Type Formats  
Facebook Audience Network
Real-time CPM
Banner, Interstitial, MREC, Rewarded
Adapter | SDK
Vungle
Real-time CPM
Banner, Interstitial, MREC, Rewarded
Adapter | SDK
InMobi Audience Bidding
Real-time CPM
Banner, Interstitial, MREC, Rewarded, Native (iOS)
Adapter | SDK
Mintegral
Real-time CPM
Banner, Interstitial, MREC, Rewarded
Adapter | SDK
Unity
Predicted CPM
Banner, Interstitial, MREC, Rewarded
Adapter | SDK
Applovin
Predicted CPM
Banner, Interstitial, MREC, Rewarded
Adapter | SDK
IronSource
Fixed CPM
Interstitial, Rewarded
Adapter | SDK
Google Admob
Fixed CPM
Banner, Interstitial, MREC, Rewarded, Native
Adapter | SDK
Google Ad Manager
Fixed CPM
Banner, Interstitial, MREC, Rewarded, Native
Adapter | SDK
AdColony Advanced Bidding
Real-time CPM
Banner, Interstitial, MREC, Rewarded
Adapter | SDK

Add Frameworks

In Xcode, go to build phases, select Link Binary With Libraries, click the + icon, and link the following frameworks in your project:

  • AdSupport
  • AppTrackingTransparency
  • AudioToolbox
  • AVFoundation
  • CoreGraphics
  • CoreMedia
  • CoreMotion
  • CoreTelephony
  • Foundation
  • MessageU
  • Ilibz
  • SafariServices
  • StoreKit
  • SystemConfiguration
  • UIKit
  • WebKit
  • MobileCoreServices

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.

For Publishers using Meta Audience Network

All publishers using Meta Audience Network and operating on iOS 14 or later must send the ATE flag. The ATE flag is for publishers to understand if the user has opted in/out to Apple’s ATT Framework.

To set this, publishers need to include the following code snippet as part of their initialisation code.

Swift

#warning("Import the following frameworks")
import AppTrackingTransparency
import FBAudienceNetwork

#warning("Call it before Meson SDK initialization")
 static func updateMetaTrackingStatus() {
        if #available(iOS 14, *) {
            if ATTrackingManager.trackingAuthorizationStatus == .authorized {
                FBAdSettings.setAdvertiserTrackingEnabled(true)
            }
        }
 }

Objective-C

#warning("Import the following frameworks")
@import AppTrackingTransparency;
@import FBAudienceNetwork;

#warning("Call this method before Meson SDK init")
+(void)updateMetaTrackingStatus {
    if (@available(iOS 14, *)) {
        if ([ATTrackingManager trackingAuthorizationStatus] == ATTrackingManagerAuthorizationStatusAuthorized) {
            [FBAdSettings setAdvertiserTrackingEnabled:YES];
        }
    }
}

Initialize the SDK

Deprecated API

Constants

  • MesonConstant.MESON_GDPR_CONSENT_AVAILABLE - Replace with MesonConstant.GDPR_CONSENT_AVAILABLE
  • MesonConstant.MESON_GDPR_CONSENT_IAB - Replace with MesonConstant.GDPR_CONSENT
  • MesonConstant.MESON_GDPR_CONSENT_GDPR_APPLIES - Replace with MesonConstant.GDPR

Initializers

  • MesonSdkConfiguration.init(appId: String, consent: [String: Any]) - This will be removed in future version.
  • MesonSdkConfiguration.init(appId: String, consent: [String: Any], buildType: MesonBuildType) - This will be removed in future version.

Initialize

To initialize the SDK, invoke the initialize method from the MesonClass. It is imperative to ensure the successful initialization of the SDK before proceeding with any other operations.

MesonSdkConfiguration

Swift

import UIKit 
import MesonSDK 

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Setting Log level
        Meson.setLogLevel(.debug)
        
        initializeMesonSDK()
        
        return true
    }
    
    private func initializeMesonSDK() {
        #warning("Please add your App ID")
        let config = MesonSdkConfiguration(appId: "<APP_ID>")
        Meson.initialize(sdkConfiguration: config) { error in
            if let error = error as NSError?, let initializeError = MesonInitializationError.init(rawValue: error.code) {
                print("Meson failed to initialize with error \(initializeError)")
                return
            }
            print("Meson \(Meson.getSDKVersion()) 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 {
    #warning("Please add your App ID")
    MesonSdkConfiguration *sdkConfiguration = [[MesonSdkConfiguration alloc] initWithAppId:@"appId"];

 
     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];