Inline Ads

Inline Ads, commonly referred to as “banners” or “rectangles”, are ad units that appear inline with other app content. Inline Ads are often found at the top or bottom of your screen while reading articles and searching through content. We recommend using Inline Ads on both smartphones and tablets in cases where the user is reading and/or interacting with content on the same screen for a period of time.

Basic Integration

NOTE: Items in source like <YOUR_PLACEMENT_ID> must be replaced with your information.

1. Add the following code to the appropriate place in your view controller’s .h or .swift file.

Objective-C

#import <UIKit/UIKit.h>
#import <MMAdSDK/MMAdSDK.h>

@interface ViewController : UIViewController <MMInlineDelegate>    

@property (strong, nonatomic) MMInlineAd *inlineAd;  

@end

Swift

class ViewController : UIViewController, MMInlineDelegate
{
    var inlineAd: MMInlineAd!
}
2. Add the following code to the appropriate place in your view controller’s .m or .swift file.

Objective-C

- (void)viewDidLoad {
    [super viewDidLoad];

    // This code will automatically determine the size of your device and display the appropriate ad size.
    MMInlineAdSize adSize = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) ? MMInlineAdSizeBanner :MMInlineAdSizeLeaderboard;

    self.inlineAd = [[MMInlineAd alloc] initWithPlacementId:@"<YOUR_PLACEMENT_ID>"
                                                     adSize:adSize]; 
    self.inlineAd.delegate = self;
    [self.view addSubview:self.inlineAd.view];
    [self.inlineAd request:nil];
}

- (UIViewController *)viewControllerForPresentingModalView {
    return self;
}

- (void)dealloc {
   [_inlineAd removeFromSuperview];
   _inlineAd.delegate = nil;
   _inlineAd = nil;
}

Swift

override func viewDidLoad() {
    super.viewDidLoad()

    // This code will automatically determine the size of your device and display the appropriate ad size.
    let adSize = (UIDevice.current.userInterfaceIdiom == .phone) ? .banner : .leaderboard
    
    self.inlineAd = MMInlineAd(placementId: "<YOUR_PLACEMENT_ID>", adSize: adSize)!

    self.inlineAd.delegate = self
    self.adContainer!.addSubview(self.inlineAd.view)
    self.inlineAd.request(nil)
}

func viewControllerForPresentingModalView() -> UIViewController {
    return self
}

Additional Topics