Skip to content

Commit

Permalink
max mrec support
Browse files Browse the repository at this point in the history
  • Loading branch information
tiandrew committed May 14, 2020
1 parent 5ff5c64 commit 6c16ea5
Show file tree
Hide file tree
Showing 11 changed files with 490 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// ALAutoLayoutMrecAdViewController.m
// DemoApp-ObjC
//
// Created by Andrew Tian on 1/14/20.
// Copyright © 2020 AppLovin Corporation. All rights reserved.
//

#import "ALAutoLayoutMrecAdViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>

@interface ALAutoLayoutMrecAdViewController()<MAAdViewAdDelegate>
@property (nonatomic, strong) MAAdView *adView;
@end

@implementation ALAutoLayoutMrecAdViewController

#pragma mark - View Lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"YOUR_AD_UNIT_ID" adFormat: MAAdFormat.mrec];
self.adView.delegate = self;
self.adView.translatesAutoresizingMaskIntoConstraints = NO;

// Set background or background color for MRECs to be fully functional
self.adView.backgroundColor = UIColor.blackColor;

[self.view addSubview: self.adView];

// Center the MREC and anchor it to the top of the screen.
[[self.adView.centerXAnchor constraintEqualToAnchor: self.view.centerXAnchor] setActive: YES];
[[self.adView.topAnchor constraintEqualToAnchor: self.view.topAnchor] setActive: YES];

[[self.adView.widthAnchor constraintEqualToConstant: 300] setActive: YES];
[[self.adView.heightAnchor constraintEqualToConstant: 250] setActive: YES];

// Load the first ad
[self.adView loadAd];
}

#pragma mark - MAAdDelegate Protocol

- (void)didLoadAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withErrorCode:(NSInteger)errorCode
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didDisplayAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didHideAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didClickAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didFailToDisplayAd:(MAAd *)ad withErrorCode:(NSInteger)errorCode
{
[self logCallback: __PRETTY_FUNCTION__];
}

#pragma mark - MAAdViewAdDelegate Protocol

- (void)didExpandAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didCollapseAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ALAutoLayoutMrecAdViewController.h
// DemoApp-ObjC
//
// Created by Andrew Tian on 1/14/20.
// Copyright © 2020 AppLovin Corporation. All rights reserved.
//

#import "ALBaseAdViewController.h"

NS_ASSUME_NONNULL_BEGIN

@interface ALAutoLayoutMrecAdViewController : ALBaseAdViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ALFrameLayoutMrecAdViewController.h
// DemoApp-ObjC
//
// Created by Andrew Tian on 1/23/20.
// Copyright © 2020 AppLovin Corporation. All rights reserved.
//

#import "ALBaseAdViewController.h"

NS_ASSUME_NONNULL_BEGIN

@interface ALFrameLayoutMrecAdViewController : ALBaseAdViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// ALFrameLayoutMrecAdViewController.m
// DemoApp-ObjC
//
// Created by Andrew Tian on 1/23/20.
// Copyright © 2020 AppLovin Corporation. All rights reserved.
//

#import "ALFrameLayoutMrecAdViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>

@interface ALFrameLayoutMrecAdViewController()<MAAdViewAdDelegate>
@property (nonatomic, strong) MAAdView *adView;
@end

@implementation ALFrameLayoutMrecAdViewController

#pragma mark - View Lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"YOUR_AD_UNIT_ID" adFormat: MAAdFormat.mrec];
self.adView.delegate = self;

// Dimensions
CGFloat width = 300;
CGFloat height = 250;
CGFloat x = self.view.center.x - 150;
CGFloat y = 0;

self.adView.frame = CGRectMake(x, y, width, height);

// Set background or background color for MRECs to be fully functional
self.adView.backgroundColor = UIColor.blackColor;

[self.view addSubview: self.adView];

// Load the first ad
[self.adView loadAd];
}

#pragma mark - MAAdDelegate Protocol

- (void)didLoadAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withErrorCode:(NSInteger)errorCode
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didDisplayAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didHideAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didClickAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didFailToDisplayAd:(MAAd *)ad withErrorCode:(NSInteger)errorCode
{
[self logCallback: __PRETTY_FUNCTION__];
}

#pragma mark - MAAdViewAdDelegate Protocol

- (void)didExpandAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didCollapseAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ALInterfaceBuilderMrecAdViewController.h
// DemoApp-ObjC
//
// Created by Andrew Tian on 1/23/20.
// Copyright © 2020 AppLovin Corporation. All rights reserved.
//

#import "ALBaseAdViewController.h"

NS_ASSUME_NONNULL_BEGIN

@interface ALInterfaceBuilderMrecAdViewController : ALBaseAdViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// ALInterfaceBuilderMrecAdViewController.m
// DemoApp-ObjC
//
// Created by Andrew Tian on 1/23/20.
// Copyright © 2020 AppLovin Corporation. All rights reserved.
//

#import "ALInterfaceBuilderMrecAdViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>

@interface ALInterfaceBuilderMrecAdViewController()<MAAdViewAdDelegate>
@property (nonatomic, strong) IBOutlet MAAdView *adView;
@end

@implementation ALInterfaceBuilderMrecAdViewController

#pragma mark - View Lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

// NOTE: Must set Storyboard "User Defined Runtime Attributes" for MREC ad view
// Key Path = ad_unit_id
// Type = String
// Value = YOUR_AD_UNIT_ID

// Load the first ad
[self.adView loadAd];
}

#pragma mark - MAAdDelegate Protocol

- (void)didLoadAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withErrorCode:(NSInteger)errorCode
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didDisplayAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didHideAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didClickAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didFailToDisplayAd:(MAAd *)ad withErrorCode:(NSInteger)errorCode
{
[self logCallback: __PRETTY_FUNCTION__];
}

#pragma mark - MAAdViewAdDelegate Protocol

- (void)didExpandAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

- (void)didCollapseAd:(MAAd *)ad
{
[self logCallback: __PRETTY_FUNCTION__];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,18 @@ - (void)viewDidLoad

[self.view addSubview: self.adView];

// Center the banner and anchor it to the top of the screen.
CGFloat height = (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) ? 90 : 50; // Banner height on iPhone and iPad is 50 and 90, respectively
[self.view addConstraints: @[[self constraintWithAdView: self.adView andAttribute: NSLayoutAttributeLeading],
[self constraintWithAdView: self.adView andAttribute: NSLayoutAttributeTrailing],
[self constraintWithAdView: self.adView andAttribute: NSLayoutAttributeTop],
[NSLayoutConstraint constraintWithItem: self.adView
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 1.0
constant: height]]];

// Anchor the banner to the left, right, and top of the screen.
[[self.adView.leadingAnchor constraintEqualToAnchor: self.view.leadingAnchor] setActive: YES];
[[self.adView.trailingAnchor constraintEqualToAnchor: self.view.trailingAnchor] setActive: YES];
[[self.adView.topAnchor constraintEqualToAnchor: self.view.topAnchor] setActive: YES];

[[self.adView.widthAnchor constraintEqualToAnchor: self.view.widthAnchor] setActive: YES];
[[self.adView.heightAnchor constraintEqualToConstant: UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad ? 90 : 50 ] setActive: YES];

// Load the first ad
[self.adView loadAd];
}

- (NSLayoutConstraint *)constraintWithAdView:(MAAdView *)adView andAttribute:(NSLayoutAttribute)attribute
{
return [NSLayoutConstraint constraintWithItem: adView
attribute: attribute
relatedBy: NSLayoutRelationEqual
toItem: self.view
attribute: attribute
multiplier: 1.0
constant: 0.0];
}

#pragma mark - MAAdDelegate Protocol

- (void)didLoadAd:(MAAd *)ad
Expand Down
Loading

0 comments on commit 6c16ea5

Please sign in to comment.