Introduction

This page will help you integrate the Media.Net Ad SDK into your iOS project. You can reach us at mobileapps@media.net if you have any queries during integration.

Supported Versions

The ad-sdk can be integrated into apps with the minimum pre-requisites of -

  • Target iOS 8.0 or above
  • XCode 8.0 or above

There are 2 steps to the process:

  • Download and incorporate the Media.Net SDK
    • Either one of these approaches -
      • Using CocoaPods (Recommended)
      • Manual Integration
  • Initialising the SDK

Integration Steps

1. Download and incorporate the Media.Net SDK

There are two ways of incorporating the Media.Net SDK into your project. You can integrate using CocoaPods, a popular dependency management system for Objective-C projects, or you can integrate it manually. Both the methods are described below.

The Media.Net SDK is available through Cocoapods

To download and incorporate the Media.Net SDK into your project using Cocoapods, add the following line to your project’s podfile:

pod 'MNetAdSdk', :git=> 'https://github.com/media-net/mnet-ad-sdk', :tag=> '1.0.0'

Run pod install (if you’re setting up Cocoapods for the first time) or pod update (if you’re adding Media.Net SDK to an existing Cocoapods project) to get your project ready to use the base Media.Net SDK.

Manual Integration

  • Download the framework file from here.

  • Unzip the downloaded file to get the framework. You can add the MNetAdSdk.framework to your project, by dragging-and-dropping it onto the required group in Xcode.

  • Make sure that you add these frameworks, which are mandatory requirement for MNetAdSdk to work properly.

  • CoreLocation.framework
  • WebKit.framework
  • AdSupport.framework
  • MobileCoreServices.framework
  • SystemConfiguration.framework
  • CoreTelephony.framework
  • AVFoundation.framework
  • CoreMedia.framework
  • Security.framework
  • AVKit.framework
  • EventKit.framework
  • EventKitUI.framework
  • Photos.framework
  • SafariServices.framework

  • Make sure that you have added ‘-ObjC’ linker flag in ‘Other Linker Flags’ of project’s target build settings.

2. Initialising the SDK

Initialise the SDK by passing the customer ID to initWithCustomerId: method in the MNet interface. Ideally this should be done from your application’s AppDelegate implementation (more specifically inside the application:didFinishLaunchingWithOptions: method).

If your app contains child directed content, you can specify that in the initialization itself, by alternatively, using the initWithCustomerId: appContainsChildDirectedContent:, which accepts a boolean as a paramter.

This example illustrates that -

Objective-C

@import MNetAdSdk;

@implementation DemoAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Initializing the MNetAdSdk by passing the customer-id - DEMO_MN_CUSTOMER_ID
    [MNet initWithCustomerId: DEMO_MN_CUSTOMER_ID];
    return YES;
}
...

Swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        MNet.initWithCustomerId(DemoConstants.DEMO_MN_CUSTOMER_ID)
        return true
    }
...

Optionally, You can also add user specific information as well, which would be useful in providing context for the ads. If you want to test out the ads, you can set the test flag on the MNet object.

Here is a complete example -

Objective-C

@import MNetAdSdk;

@implementation DemoAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Initializing the MNetAdSdk by passing the customer-id DEMO_MN_CUSTOMER_ID
    MNet *mnetObj = [MNet initWithCustomerId: DEMO_MN_CUSTOMER_ID];

    // Adding user details
    MNetUser *user = [MNetUser new];
    [user addGender:MNetGenderFemale];
    [user addKeywords:@"fruits, health, energy"];
    [user addYearOfBirth:@"1985"];
    [user addName:@"Demo User"];
    [user addUserId:@"test-id"];
    [mnetObj setUser:user];

    // Load test ads
    [mnetObj setIsTest:YES];

    // Logs all MNetAdSdk related messages.
    // It is set to NO by default.
    // *** Do NOT set this to yes in production. It will affect performance ***
    // Call this method only if the debugging is required.
    // [MNet enableLogs:YES];

    return YES;
}

Swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Initializing the MNetAdSdk by passing the customer ID (DEMO_MN_CUSTOMER_ID)
        let mnetObj = MNet.initWithCustomerId(DemoConstants.DEMO_MN_CUSTOMER_ID)

        // Adding user details
        let user = MNetUser()
        user.addGender(MNetGenderFemale)
        user.addKeywords("fruits, health, energy")
        user.addName("Demo User")
        user.addUserId("test-id")
        user.addYear(ofBirth: "1985")
        mnetObj.user = user

        // Logs all MNetAdSdk related messages.
        // It is set to NO by default.
        // *** Do NOT set this to true in production. It will affect performance ***
        // Call this method only if the debugging is required.
        // MNet.enableLogs(true)

        return true
    }

GDPR

You can use the following function to pass the GDPR consent details to the SDK.

/// Call this method to set the consent for Media.Net.
/// Parameters -
/// ConsentString - NSString representing the consent string
/// ConsentStatus - An enum to specify the consent status.
///                 Enum options -
///                 MNetGdprConsentStatusUnknown // Consent is UNKNOWN
///                 MNetGdprConsentStatusGiven   // Consented
///                 MNetGdprConsentStatusRevoked // Not consented
/// SubjectToGdpr - An enum to specify if subject to GDPR
///                 Enum options -
///                 MNetSubjectoToGdprUnknown     // GDPR applicability is UNKNOWN
///                 MNetSubjectToGdprDisabled     // GDPR not applicable
///                 MNetGdprConsentStatusRevoked  // GDPR applicable
+ (void)updateGdprConsentString:(NSString *)consentString
                  consentStatus:(MNetGdprConsentStatus)status
                  subjectToGdpr:(MNetSubjectToGdpr)subjectToGdpr;

Below is an example illustrating the use of the function:

Objective-C

[MNet updateGdprConsentString:@"consent-string"
                consentStatus:MNetGdprConsentStatusGiven
                subjectToGdpr:MNetSubjectToGdprEnabled];

Swift

MNet.updateGdprConsentString("consent-string",
                            consentStatus: MNetGdprConsentStatus.given,
                            subjectToGdpr: MNetSubjectToGdpr.subjectToGdprEnabled)