In-App SDK Integration Guide: iOS

You can connect your mobile app directly to premium brand demand through the DV+ ecosystem with the Magnite in-App SDK.

With this lightweight, reliable integration layer in DV+ you get the following:

  • Direct, prioritized, differentiated access to Magnite’s marketplace
  • Transparent, privacy-safe monetization aligned with global regulations
  • Unified cross-channel value, allowing mobile supply to participate seamlessly alongside CTV

The information below describes the basic procedure for integrating Magnite in-app ads into your iOS apps, SDK version 1.0.0.. Find more details about Swift documentation.

Notes

  • You can copy and paste the code samples below in your source code.
  • If you need a reference, you can use this sample project.
  • When you submit your app to the App Store, remember to update your IDFA settings.
  • We recommend you run integration tests before going live.
  • If you need help or have questions, you can contact us at sdk@magnite.com.

Step 1: Add the SDK to your project

You have two options to add the SDK: with CocoaPods (recommended), or manually.

Option 1: Use CocoaPods (recommended)

Open your project’s Podfile and add this line to your app’s target:

pod 'MagniteSDK'

Run pod install from command line:

$ pod install

If you’re new to CocoaPods and need info on how to create and use Podfiles, see their documentation.

Option 2: Manual download

To manually download the iOS DSK, visit Github. Then follow the steps below:

  1. Download the SDK, then right-click your project and choose “Add Files to…”

  2. Add the Magnite SDK files:

    • MagniteSDK.xcframework

  3. Make sure to check the box for “Copy items if needed”.

Then add your frameworks. Add the Magnite SDK files to your app project directory:

  • Select your app project to bring up the project editor.
  • Select your app target to bring up the target editor.
  • Select the Build Phases tab and disclose the “Link Binary with Libraries” phase, then click the plus button in that phase.
  • Add the following frameworks:
    • AdSupport.framework
    • AppTrackingTransparency
    • AVFoundation.framework
    • CoreAudio.framework
    • CoreFoundation.framework
    • CoreGraphics.framework
    • CoreMedia.framework
    • CoreTelephony.framework
    • Foundation.framework
    • JavaScriptCore.framework
    • QuartzCore.framework
    • StoreKit.framework
    • SystemConfiguration.framework
    • UIKit.framework
    • WebKit.framework
    • libz.tbd

Step 2: Initialization

In your app’s delegate class (AppDelegate.m), import the Magnite SDK and add the following line to your app’s didFinishLaunchingWithOptions function:

// AppDelegate.m
#import <MagniteSDK/MagniteSDK.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // initialize the SDK with your appID
    MGNISDK* sdk = [MGNISDK sharedInstance];
    sdk.appID = @"your app Id";
    return YES;
}

Replace “your app Id” with the value that we’ll give you at onboarding.

Step 3: User consent (GDPR)

You need to pass the user consent flag with the API as described below. The user consent flag indicates whether a user in the EU has given consent for ads personalization, collection, and use of personal data. Based on this consent flag, we’ll be able to use the data to target the most relevant ads to your users. If a user hasn’t consented, we won’t show personalized ads to this user.

Important:

  • Collection of consent is only required in countries covered by GDPR (EU member states). Consent isn’t required for users based outside those countries.
  • We recommend that you pass the consent flag to Magnite right after initializing the SDK.
  • In case of any consent change during the lifetime of the user activity, you must resubmit the relevant consent flag to Magnite.

Use this method if the user has consented:

[[MGNISDK sharedInstance] setUserConsent:YES forConsentType:@"pas"
withTimestamp:[[NSDate date] timeIntervalSince1970]];

Use this method if the user hasn’t consented:

[[MGNISDK sharedInstance] setUserConsent:NO forConsentType:@"pas"
withTimestamp:[[NSDate date] timeIntervalSince1970]];

The timestamp parameter should represent the specific time a consent was given by the user.

To make the process easier, we’ve added a consent window to our demo apps. See demo projects.

Step 4: CCPA compliance

Magnite’s SDK supports publishers to restrict the sale of end users’ personal information under the California Consumer Privacy Act (CCPA).

The notification about opt-out of specific users located in California should be handled based on IAB US Privacy String.

To set the IAB US privacy string, use the following API:

MGNISDK *sdk = [MGNISDK sharedInstance];
[sdk handleExtras:^(NSMutableDictionary<NSString*,id>* extras) {
    [extras setObject:@"1YNN" forKey:@"IABUSPrivacy_String"];
}];

To determine what value to use, refer to this IAB compliance document. Note that it is case-sensitive.

  • When CCPA doesn’t apply (e.g. if the user isn’t a resident of California), you can either skip this API or use the following value “1—.”
  • If the user chooses not to opt out and is okay with advertising as usual, use “1YNN.”
  • If the user chooses to restrict advertising and opt out, use “1YYN.”

Interstitial Ads

Interstitial Ads are full page ads, displayed before or after a certain content page or action, such as upon entering a stage, between stages, while waiting for an action, upon exiting the application and more. When integrating this ad type you are open to get both Display or Video ads. Our optimization will auto-select the ad type that will generate the most revenue for you.

In order to show Rewarded Video Ads in your app, follow the following steps:

First, declare MGNIAd instance:

// YourViewController.h
#import <MagniteSDK/MagniteSDK.h>
@interface YourViewController : UIViewController
{
    MGNIAd* magniteInterstitialAd;    // ADD THIS LINE
}

Use the "loadAdWithDelegate" method:

// YourViewController.m 
- (void)viewDidLoad {
    [super viewDidLoad];
    magniteInterstitialAd = [[MGNIAd alloc] init];
    [magniteInterstitialAd loadAdWithDelegate:self];
}

Then, you can implement the following method in order to get a callback when ad is loaded and ready to be shown:

- (void)didLoadAd:(MGNIAbstractAd*)ad;

Finally, add the following lines where you want to show the ad

[magniteInterstitialAd showAd];

Important

Loading an ad might take a few seconds so it's important to show the ad as late as you can. In case you call showAd() while the ad hasn't been successfully loaded yet, nothing will be displayed. For example, if you'd like to show an ad after completing a game's level, the best practice would be to show the ad upon completing the level (for example in your viewDidDisappear() function). On the other hand, loading and showing the ad together at the beginning of the next level might result with a failure – as the ad might not have enough time to load. 

Rewarded Video Ads

Rewarded Ads are interstitial video ads that provide a reward to the user in exchange for watching an entire video ad. The reward might be in-app goods, virtual currency or any premium content provided by the application. Because users actually opt-in to watch a rewarded video and are granted with something valuable in return, Rewarded Ads are an effective and clean monetization solution for stronger user retention and keeping users engaged in your application for a longer amount of time.

In order to show Rewarded Video Ads in your app, follow the following steps:

First, declare MGNIAd instance:

// YourViewController.h
#import <MagniteSDK/MagniteSDK.h>
@interface YourViewController : UIViewController
{
    MGNIAd* magniteRewardedVideoAd;    // ADD THIS LINE
}

Use the "loadRewardedVideoAdWithDelegate" method:

// YourViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
    magniteRewardedVideoAd = [[MGNIAd alloc] init];
    [magniteRewardedVideoAd loadRewardedVideoAdWithDelegate:self];
}

Then, you can implement the following method in order to get a callback when the user completes watching the video and is eligible for getting the reward:

- (void) didCompleteVideo:(MGNIAbstractAd*)ad;

Finally, add the following line where you want to show the ad

[magniteRewardedVideoAd showAd];

Native Ads

A "Native Ad" is a raw representation of an ad without any pre-defined wrapping UI, which gives you the freedom to design and control the ad exactly as you want. Using Native Ads, you can design an ad experience that perfectly fits your application's scene, content and functionality.

For a full integration guide, please refer to this Advanced Usage section in the Appendix.

Banner Ads

To display banners in your app, add a STABannerView to your application according to the following steps:

1. In the header file of your view controller, import MGNIBannerView.h and MGNIBannerSize.h and declare an MGNIBannerView instance variable

// YourViewController.h 
#import <UIKit/UIKit.h>
#import <MagniteSDK/MagniteSDK.h>
@interface YourViewController : UIViewController
{
    MGNIBannerView* bannerView;
}

2. Create and initialize the MGNIBannerView and add it as a subView to the view where you want it to be displayed. Remember to release the bannerView object in your dealloc() function in case you're not using ARC in your project

// YourViewController.m
- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
     if (bannerView == nil) {
        bannerView = [[MGNIBannerView alloc] initWithSize:MGNIBannerSizeAuto
                                            autoOrigin:MGNIBannerAutoOriginTop    
                                            withDelegate:nil];
        [self.view addSubview:bannerView];
    }
}

The MGNIBannerSize detects the width of the device's screen in its current orientation, and provides the optimal banner for this size.

Note:

  • You can find your "developerId" and "appId" the same way as in Step 2 above
  • This example shows the banner at the top of the root view controller (self.view), but you can pass any other view where you want to show the banner

Positioning the banner

The origin of the banner is determined by the "autoOrigin" parameter which can receive one of the following values

ValuePositionBehavior

MGNIBannerAutoOriginTop

Auto Top

The banner will be centered and pinned to the top of the view. In case the view is a root view controller, the banner will be located under the status bar, if exists.

MGNIBannerAutoOriginBottom

Auto Bottom

The banner will be centered and pinned to the bottom of the view.

If you wish to use a fixed origin for the banner, please refer to the Advanced Usage section in the Appendix.

MRec Ads

MRec is a 300X250 rectangular ad integrated within an app's layout. The ad will be refreshed automatically.

In order to integrate an MRec ad inside your app, you can refer to the “Banner Ads” section above and initiate it with the specific size: MGNIBannerSizeMRec300x250.

Swift iOS integration

The information below describes the basic procedure for integrating Magnite in-app ads into your iOS applications written in Swift programming language. 

After this simple integration process, Magnite in-App Ads SDK enables you to reap the benefits of Magnite's in-app monetization products, which maximize the revenue generated by your application. All this profit-making is achieved with minimal effort and minimal interference with your users’ experience.

NOTES:

  • You can also checkout our sample project here
  • When submitting your application to the App Store, do not forget to update your IDFA Settings.
  • We strongly recommend you incorporate integration tests during the integration and before going live
  • Please notice that steps 1-3 are mandatory
  • If you have any questions, contact us at sdk@magnite.com

Getting Started

Step 1: Downloading the latest Magnite SDK

CocoaPods

Open your project's Podfile and add this line to your app's target:

$ pod 'MagniteSDK'

Run pod install from command line:

$ pod install

If you're new to CocoaPods, see their official documentation for info on how to create and use Podfiles.

Manual download

Add the Magnite SDK files to your application project directory

  1. Right-click on you project and choose "Add Files to…" 

  2. Add the Magnite SDK files:

MagniteSDK.xcframework

Make sure to check the "Copy items if needed" checkbox.

Step 2: Adding frameworks

Add necessary frameworks to your target project

  1. Select your application project to bring up the project editor

  2. Select your application target to bring up the target editor

  3. Select the Build Phases tab and disclose the "Link Binary with Libraries" phase and click the plus button in that phase

4.     Add the following frameworks:

  • AdSupport.framework
  • AppTrackingTransparency
  • AVFoundation.framework
  • CoreAudio.framework
  • CoreFoundation.framework
  • CoreGraphics.framework
  • CoreMedia.framework
  • CoreTelephony.framework
  • Foundation.framework
  • JavaScriptCore.framework
  • QuartzCore.framework
  • StoreKit.framework
  • SystemConfiguration.framework
  • UIKit.framework
  • WebKit.framework
  • libz.tbd
     

Step 3, Adding the Bridging-Header file

To create or edit your application's Bridging-Header file, follow the following steps:

  1. Right-click your project and choose “New File…”

  1. Choose iOS->Source->Header File->Next

  1. Name the file "<YourProduct>-Bridging-Header.h”

where <YourProduct> should be identical to the one being used in your build's settings

4.     Make sure the Bridging Header is declared in "Build Settings" with the right path

5.     Import the following header file:

#import <MagniteSDK/MagniteSDK.h>

Step 4, Initialization

In your application delegate class (AppDelegate.swift), add the following code to your applicationmethod:

// AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // initialize the SDK with your appID and devID
        var sdk: MGNISDK = MGNISDK.sharedInstance()
        sdk.appID = "Your App Id"
        return true
    }

Replace "your app id" with your own the value Magnite will provide upon onboarding

 Interstitial Ads

You can choose to show the Interstitial Ad in several locations within your application. This could be between stages, while waiting for an action, when pressing a button and more.

In your view controller declare an MGNIAd at the begin of the class. Init the MGNIAd using the viewDidLoad() method and load it within the viewDidAppear() method.

var magniteInterstitialAd: MGNIAd?
override func viewDidLoad() {
        super.viewDidLoad()
        magniteInterstitialAd = MGNIAd()
    }
override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        magniteInterstitialAd!.loadAd()
    }

Finally, add the following lines where you want to show the ad:

magniteInterstitialAd!.showAd()

IMPORTANT

Loading an ad might take a few seconds so it's important to show the ad as late as you can. In case you call showAd() while the ad hasn't been successfully loaded yet, nothing will be displayed. For example, if you'd like to show an ad after completing a game's level, the best practice would be to show the ad upon completing the level (for example in your viewDidDisappear() method). On the other hand, loading and showing the ad together at the beginning of the next level might result with a failure – as the ad might not have enough time to load.

Rewarded Video Ad

Rewarded Ads are interstitial video ads that provide a reward to the user in exchange for watching an entire video ad. The reward might be in-App goods, virtual currency or any premium content provided by the application. Because users actually opt-in to watch a rewarded video and are granted with something valuable in return, Rewarded Ads are an effective and clean monetization solution for stronger user retention and keeping users engaged in your application for a longer amount of time.

In order to integrate Rewarded Videos in your app do the following:

First, Declare MGNIAd instance:

class ViewController: UIViewController, MGNIDelegateProtocol {
    // Declaration of Magnite Rewarded ad
    var magniteRewardedAd: MGNIAd?
} 

Use the "loadRewardedVideoAd" method:

override func viewDidLoad() {
    super.viewDidLoad()
    magniteRewardedAd = MGNIAd()
    // Loading the ad
    magniteRewardedAd!.loadRewardedVideoAd(withDelegate: self);
}

Then, you can implement the following method in order to get a callback when the user completes watching the video and is eligible for getting the reward:

func didCompleteVideo(_ad: MGNIAbstractAd) {
   print("MAgnite rewarded video had been completed", terminator: "")
}

Finally, add the following lines where you want to show the ad

magniteRewardedAd!.show()

Banner Ad

To display banners in your app, follow the following steps:

1 In your view controller declare MGNIBannerView at the beginning of the class.

// ViewController.swift 
var magniteBanner: MGNIBannerView?

2 Create and initialize your MGNIBannerView variable and add it as a subView to the view where you want it to be displayed.

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        if (magniteBanner == nil) {
            magniteBanner = MGNIBannerView(size: MGNIBannerSizeAuto, autoOrigin: MGNIBannerAutoOriginBottom, withView: self.view, withDelegate: nil);
            self.view.addSubview(magniteBanner!)
        }
    }

The MGNIBannerSizeAuto detects the width of the device's screen in its current orientation, and provides the optimal banner for this size.

NOTE:

This example shows the banner at the bottom of the root view controller (self.view), but you can pass any other view where you want to show the banner

Steps 3 and 4 are required only in case your app supports both orientations.

3 Implement didRotateFromInterfaceOrientation in your view controller

// YourViewController.swift 
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation)  {
        // notify Magnite auto Banner orientation change           
        magniteBanner!.didRotateFromInterfaceOrientation(fromInterfaceOrientation)       
        super.didRotateFromInterfaceOrientation(fromInterfaceOrientation)
    }

4 If your app supports iOS 8, implement viewWillTransitionToSize in your view controller

// YourViewController.m
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        // notify magniteApp auto Banner orientation change
        magniteBanner!.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
     
        super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
    }

Positioning the banner

The origin of the banner is determined by the "autoOrigin" parameter which can receive one of the following values

Value

Position

Behavior

MGNIBannerAutoOriginTop

Auto Top

The banner will be centered and pinned to the top of the view. In case the view is a root view controller, the banner will be located under the status bar, if exists.

MGNIBannerAutoOriginBottom

Auto Bottom

The banner will be centered and pinned to the bottom of the view.

 

NOTE

If you wish to use a fixed origin for the banner, please refer to the Advanced Usage section below

Sample Project

Magnite provides a sample Swift integration project available on GitHub 

Advanced Usage

For advanced usage, please read the Advanced Usage appendix section below

-----------

Advanced Usage

Appendix

Interstitial Ads

Implementing Interstitial Ads with objects

You can implement an Interstitial Ad as an object if you need to gain more control over your ads, like using callbacks or using multiple ads with different properties.

First, import the Magnite SDK in your view controller and add the following lines to the header file for each view in which you would like to show an ad

// YourViewController.h
#import <MagniteSDK/MagniteSDK.h>
@interface YourViewController : UIViewController
{
    MGNIAd* magniteAd;    // ADD THIS LINE
}

In your view controller init MGNIAd within the viewDidLoad() method and load it within the viewDidAppear() method. Remember to release the MGNIAd object in your dealloc()method in case you're not using ARC in your project.

// YourViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
    magniteAd = [[MGNIAd alloc] init];
}
- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [magniteAd loadAd];  // Add this line
} 

Finally, add the following lines where you want to show the ad

[magniteAd showAd];

IMPORTANT

Loading an ad might take a few seconds so it's important to show the ad as late as you can. In case you call showAd() while the ad hasn't been successfully loaded yet, nothing will be displayed. For example, if you'd like to show an ad after completing a game's level, the best practice would be to show the ad upon completing the level (for example in your viewDidDisappear() function). On the other hand, loading and showing the ad together at the beginning of the next level might result in a failure – as the ad might not have enough time to load.

Implementing interstitial video ads with objects

We highly recommend using our Automatic mode, which automatically selects the best Interstitial Ad to display, meaning the type of Ads that will generate the most revenue for you. To add an automatic Interstitial Ad, please refer to Interstitial Ads sections.

If you wish to get Video ads only, add the following code to the appropriate place or places in which you would like to show the video ad:

Example:

magniteAd = [[MGNIAd alloc] init];
[magniteAd loadVideoAd];

Finally, add the following lines where you want to show the ad

[magniteAd showAd];

Using Interstitial delegates

Set your view controller as a delegate so it is able to receive callbacks from the Interstitial Ad.

  1. Add the MGNIDelegateProtocol to the header file
    @interface YourViewController : UIViewController
    {
    MGNIAd* magniteAd;   
    }
  2. Use "withDelegate:self" when calling the loadAd function: [magntieAd loadAdwithDelegate:self]
  3. Implement the following functions:
- (void) didLoadAd:(MGNIAbstractAd*)ad;
- (void) failedLoadAd:(MGNIAbstractAd *)ad withError:(NSError *)error;
- (void) didShowAd:(MGNIAbstractAd *)ad;
- (void) failedShowAd:(MGNIAbstractAd *)ad withError:(NSError *)error;
- (void) didCloseAd:(MGNIAbstractAd *)ad;
- (void) didClickAd:(MGNIAbstractAd *)ad;

Banner Ads

Loading a Banner

You can load a banner without attaching it to a view, enabling you to attach it when available in a later stage:

 [banner loadAd]; 

Once banner is loaded, bannerAdIsReadyToDisplay: delegate method will be called.

Hiding your banner

You can hide and show your banner in run time, using showBanner and hideBanner methods:

[bannerView showBanner];
[bannerView hideBanner]; 

Controlling the size of your banner

The size of the banner is determined by the "size" parameter which can receive one of the following values

Value

Size

Best fits for

MGNIBannerSizeAuto

Auto-size (recommended)

detects the width of the device's screen in its current orientation, and provides the optimal banner for this size

MGNIBannerSizePortrait320x50

320x50

iPhone/iPod touch in portrait mode

MGNIBannerSizeLandscape480x50

480x50

iPhone/iPod touch in landscape mode

MGNIBannerSizeMRec300x250

300x250

iPhone/iPod touch, Medium Rectangle

MGNIBannerSizeCover300х157

1200X628

iPhone/iPod touch, Cover

MGNIBannerSizePortrait768x90

768x90

iPad in portrait mode

MGNIBannerSizeLandscape1024x90

1024x90

iPad in landscape mode

Using banner delegates

Set your view controller as a delegate so it is able to receive callbacks from the banner ad.

  1. Add the MGNIBannerDelegateProtocol to the header file

@interface YourViewController : UIViewController
{
    MGNIBannerView* bannerView; 
}
  1. Use "withDelegate:self" when initializing the MGNIBannerView object:

bannerView = [[MGNIBannerView alloc] initWithSize:MGNIBannerSizeAuto
                                     autoOrigin:MGNIBannerAutoOriginTop                
                                     withDelegate:self];
  1. Implement the following functions:

- (void) didDisplayBannerAd:(MGNIBannerViewBase*)banner;
- (void) failedLoadBannerAd:(MGNIBannerViewBase *)banner withError:(NSError *)error;
- (void) didClickBannerAd:(MGNIBannerViewBase *)banner;

Using a fixed origin for your banner

If you choose to locate the banner in a fixed origin rather than the view's top or bottom, simply pass the required origin point (x,y) upon initialization as explain in the following example

Locating your banner 100 pixels above the view's bottom:

bannerView = [[MGNIBannerView alloc] initWithSize:MGNIBannerSizeAuto
                                    origin:CGPointMake(0, self.view.frame.size.height - 100)
                                    withDelegate:nil];

To use a different banner origin in a specific layout, call the "setOrigin"/"setMGNIAutoOrigin" with the new origin value.

Changing the banner size and origin upon rotation

If you choose to manually control the banner's size & origin upon rotation, you can do it in the didRotateFromInterfaceOrientation function.

Example:

// YourViewController.m
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
         [bannerView setOrigin:CGPointMake(0, 0)];
    } else { 
        [bannerView setOrigin:CGPointMake(0, 300)];
    }
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

Integrating Native Ads

Initializing and Loading Native Ads

First, import the Magnite SDK in your view controller and add the following lines to the header file for each view in which you would like to use Magnite Native ad.

// YourViewController.h
#import <MagniteSDK/MagniteSDK.h> 
@interface YourViewController : UIViewController
{
    MGNINativeAd *magniteNativeAd;    // ADD THIS LINE
}

In your view controller, initialize MGNINativeAd within the viewDidLoad() method and load the ad with your selected preferences.

// YourViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    magniteNativeAd = [[MGNINativeAd alloc] init];
    [magniteNativeAd loadAd];
}

You can check if the ad has been loaded, using magniteNativeAd.adIsLoaded;.

Using Native Ad delegates

Set your view controller as a delegate so it is able to receive callbacks from the native ad.

  1. Add the MGNIDelegateProtocol to the header file

@interface YourViewController : UIViewController
{
    MGNINativeAd *magniteNativeAd;   
}
  1. Implement the following functions

- (void) didLoadAd:(MGNIAbstractAd*)ad;
- (void) failedLoadAd:(MGNIAbstractAd*)ad withError:(NSError *)error;
  1. Load an ad using loadAdWithDelegate

[magniteNativeAd loadAdWithDelegate:self];

Using Native Ad Preferences

MGNINativeAdPreferences can be used to customize some of the native ad properties to suit your needs, such as the number of ads to load, the image size of the ad, or whether the image should be pre-cached or not. For a full description of the NativeAdPreferences object, please refer to Native Ad Preferences API section below.

In order to use the MGNINativeAdPreferences object, simply use it when loading the ad:

[magniteNativeAd loadAdWithNativeAdPreferences:pref]; 

Example: load a 150x150 ad and register for callbacks:

// YourViewController.m 
- (void)viewDidLoad
{
    [super viewDidLoad];
    magniteNativeAd = [[MGNINativeAd alloc] init];
    MGNINativeAdPreferences *pref = [[MGNINativeAdPreferences alloc]init];
    pref.primaryImageSize = MGNINativeAdBitmapSize1200x628;     // Select 1200x628 primary image
    pref.secondaryImageSize = MGNINativeAdBitmapSize150x150;     // Select 150x150 secondary icon   
    pref.autoBitmapDownload = YES;    // When set to NO no images will be downloaded by the SDK
            
    [magniteNativeAd loadAdWithDelegate:self withNativeAdPreferences:pref];
}  

Using the Native Ad Object

After initializing and loading your MGNINativeAd object, use the MGNINativeAdDetailsobject to get details of all returning ads. The MGNINativeAdDetails object provides access to each ad's details, such as the ad's title, description, image, etc. This object also provides methods for firing an impression once the ad is displayed, and for executing the user's click on the ad. For a full description of the MGNINativeAd object, please refer to Native Ad Details API section below.

Example: get some details of the 1st ad.

MGNINativeAdDetails *adDetails = [magniteNativeAd.adsDetails objectAtIndex:0];
TitleLabel.text = adDetails.title;
DescriptionLabel.text = adDetails.description;
ImageView.image = adDetails.imageBitmap;

Note:

It is possible to get less ads than you requested. It is also possible that no ad will be returned. In this case you will receive an empty array.

Tracking the native ad

The SDK will log the impression and handle the click automatically. Please note that you must register the ad's view with the ad object. To make all ad elements of the view clickable register it using:

[adDetails registerViewForImpressionAndClick:yourViewForClicksInterception);

Native Ad Preferences API

Parameter nameDescriptionValues
adsNumber

number of native ads to be retrieved

a number between 1-10


primaryImageSize

size of the primary image to be retrieved

Can take one of the following: 

0 - image size of 72X72 
1 - image size of 100X100
2 - image size of 150X150
3 - image size of 340X340 
4 - image size of 1200X628

secondaryImageSizesize of the icon secondary images to be retrieved


0 - image size of 72X72 
1 - image size of 100X100
2 - image size of 150X150
3 - image size of 340X340

autoBitmapDownload

Select the method for retrieving the ad's icon. You can get the icon's URL only, or pre-cache it into a bitmap object

"YES"=pre cached, "NO"=URL only

userLocation.latitude


the device's latitude

latitude

userLocation.longitude

the device's latitude

longtitude

At the moment, sizes 5-6 can't be used together with sizes 0-4.

MGNI Native Ad Details API

Parameter name

Description

Return value

title

Get the Ad's title

NSString

description

Get the Ad's description

NSString

imageBitmap

Get the actual icon of the ad, according to the selected size (if autoBitmapDownload="YES")

UIImage

imageUrl

Get the primary image URL of the ad, according to the selected size (if autoBitmapDownload="NO")

NSString

secondaryImageBitmap

Get the actual secondary image of the ad, according to the selected size (if autoBitmapDownload="YES")

UIImage

secondaryImageUrl

Get the secondary image URL of the ad, according to the selected size (if autoBitmapDownload="NO")

NSString

category

Get the category of the ad in the App Store

NSString

adId

Get the ad's internal number (for communication with AM)

NSString

rating

Get the rating of the ad in the App Store. The rating range is 1-5

NSNumber

clickToInstall

Get the call to action for the ad (either "install" or "open"

NSString

callToAction

Get a short text to place on the "call to action" button\area

NSString

Using Ad Tags

You can add tags to your ad placements. A tag is simply a free style string identifier that can be attached to any ad. Ad Tags will help you optimize your monetization by finding the right balance between ads and the perfect ad-viewing experience for your users.

For example, if you implement couple of Interstitial Ads in different places in your application, you can give each of them a different tag, one of them could be "Level1Complete", the other "AfterScoresBoard", then, you can monitor which placement convert better and get more engagement from your users.

In order to add tags, you simply need to add them to the right places in your code:

Banner: create ad preferences, set ad tag to ad preferences. Then set ad preferences to your banner view

MGNIAdPreferences *adPreferences = [[MGNIAdPreferences alloc] init];
adPreferences.adTag = @"BannerAdTagRequest";
self.bannerView = [[MGNIBannerView alloc] initWithSize:MGNIBannerSizeAuto autoOrigin:MGNIBannerAutoOriginBottom withDelegate:self];
[self.bannerView setAdPreferences:adPreferences];
[self.view addSubview:self.bannerView];

Interstitials: create ad preferences, set ad tag to ad preferences. Then load Interstitial Ad with these ad preferences:

MGNIAdPreferences* interstitialPrefs  = [[MGNIAdPreferences alloc] init];
interstitialPrefs.adTag = @"InterstitialAdTag";
self.interstitialAd = [[MGNIAd alloc] init];
[self.interstitialAd loadAdWithDelegate:self withAdPreferences:interstitialPrefs];

Native ads: create native ad preferences, set ad tag as well as other native ad preferences properties. Then load native ad with this native ad preferences

NGINativeAdPreferences *nativeAdPrefs = [[MGNINativeAdPreferences alloc] init];
nativeAdPrefs.adTag = @"NativeAdTag";
...   
self.nativeAd = [[MGNINativeAd alloc] init];
[self.nativeAd loadAdWithDelegate:self withNativeAdPreferences:nativeAdPrefs];

NOTE:

Ad Tags can only be named using English letters and no more than 200 characters

After getting traffic, you could see those tags in the portal reports automatically, without extra setup. For more information visit

Upgrading from an older SDK

  1. Remove all old MagniteSDK.xcframework from your project

  2. Clean your project

  1. Continue to add the new Magnite  SDK files to your project, as described here.

Updating your IDFA Settings

When submitting your application to the App Store you need to update its "Advertising Identifier (IDFA)" settings in order to comply with Apple advertising policy.

On the "Advertising Identifier" section:

  1. Choose "Yes" on the right pane
  2. Opt-in the "Serve advertisements within the app" checkbox
  3. Opt-in the confirmation checkbox under "Limit Ad tracking setting in iOS"