MREC
MREC is a view-based ad format that behaves differently from other Appodeal ad types. Unlike interstitial or rewarded video ads, MREC ads are displayed as views that need to be manually added to your view hierarchy.
MREC is a 300x250 banner. This type can be useful if the application interface has a large free area for placing a banner.
You can use our demo app as a reference project.
Demo App
Check If Ad Is Loaded
For MREC ads, you must use the mrec.isReady property to check if an ad is loaded and ready to display.
- Swift
- Objective-C
// MREC view
mrec.isReady
// MREC view
mrec.isReady;
Display
AppodealMRECView is a subclass of AppodealBannerView. The size of
AppodealMRECView is 300x250.
MREC ads are refreshed every 15 seconds automatically by default. To display MREC, you need to call the following code:
- Swift
- Objective-C
import UIKit
import Appodeal
class YourViewController: UIViewController, AppodealBannerViewDelegate {
override func viewDidLoad () {
super.viewDidLoad()
// required: init ad banner
let mrecView: AppodealMRECView = AppodealMRECView()
mrecView.usesSmartSizing = false
mrecView.rootViewController = self
// optional: set delegate
mrecView.delegate = self
// required: add banner to superview and call -loadAd to start banner loading
self.view.addSubview(mrecView)
mrecView.loadAd()
}
// optional: implement any of AppodealBannerViewDelegate methods
func bannerViewDidLoadAd(_ bannerView: APDBannerView, isPrecache precache: Bool) {
NSLog("bannerView was loaded")
}
func bannerView(_ bannerView: APDBannerView, didFailToLoadAdWithError error: Error) {
NSLog("bannerView failed to load");
}
func bannerViewDidInteract(_ bannerView: APDBannerView) {
NSLog("bannerView was clicked")
}
func bannerViewDidShow(_ bannerView: APDBannerView) {
NSLog("bannerView was shown")
}
func bannerViewExpired(_ bannerView: APDBannerView) {
NSLog("bannerView did expire and could not be shown")
}
}
#import "YourViewController.h"
#import <Appodeal/Appodeal.h>
@interface YourViewController () <AppodealBannerViewDelegate>
@end
@implementation YourViewController
- (void)viewDidLoad {
[super viewDidLoad];
// required: init ad banner
AppodealMRECView *mrecView = [[AppodealMRECView alloc] init];
mrecView.rootViewController = self;
// optional: set delegate
mrecView.delegate = self;
// required: add banner to superview and call loadAd to start banner loading
[self.view addSubview:mrecView];
[mrecView loadAd];
}
// optional: implement any of AppodealBannerViewDelegate methods
- (void)bannerViewDidLoadAd:(APDBannerView *)bannerView isPrecache:(BOOL)precache {
NSLog(@"Banner %@ did load!", bannerView);
}
- (void)bannerViewDidInteract:(APDBannerView *)bannerView {
NSLog(@"Banner %@ did interact", bannerView);
}
- (void)bannerView:(APDBannerView *)bannerView didFailToLoadAdWithError:(NSError *)error {
NSLog(@"Banner %@ did fail with error: %@", bannerView, error);
}
@end
Manual Caching
MREC does not support autocache.
To cache MREC use:
- Swift
- Objective-C
// MREC view
mrec.loadAd()
// MREC view
[mrec loadAd];
Read more on manual caching in our FAQ.
Callbacks
Callbacks are used to track different events of an ad's lifecycle, e.g., when a MREC has been successfully loaded or is about to appear. To get them, you need to set the delegate as follows:
- Swift
- Objective-C
//set delegate
mrecView.delegate = self
//set delegate
mrecView.delegate = self;
Usually, the class that implements banners is also the delegate class.
That's why the delegate property can be set to self.
Now you can use the following callbacs methods:
- Swift
- Objective-C
// MREC was loaded (precache flag shows if the loaded ad is precache)
func bannerViewDidLoadAd(_ bannerView: APDBannerView, isPrecache precache: Bool) {}
// MREC failed to load
func bannerView(_ bannerView: APDBannerView, didFailToLoadAdWithError error: Error) {}
// MREC was clicked
func bannerViewDidInteract(_ bannerView: APDBannerView) {}
// MREC was shown
func bannerViewDidShow(_ bannerView: APDBannerView) {}
// MREC failed to show
func bannerView(_ bannerView: APDBannerView, didFailToPresentWithError error: Error) {}
// MREC did expire and could not be shown
func bannerViewExpired(_ bannerView: APDBannerView) {}
- (void)bannerViewDidLoadAd:(APDBannerView *)bannerView isPrecache:(BOOL)precache {
// MREC was loaded (precache flag shows if the loaded ad is precache)
}
- (void)bannerView:(APDBannerView *)bannerView didFailToLoadAdWithError:(NSError *)error {
// MREC failed to load
}
- (void)bannerViewDidInteract:(APDBannerView *)bannerView {
// MREC was clicked
}
- (void)bannerViewDidShow:(APDBannerView *)bannerView {
// MREC was shown
}
- (void)bannerView:(APDBannerView *)bannerView didFailToPresentWithError:(NSError *)error {
// MREC failed to show
}
- (void)bannerViewExpired:(APDBannerView *)bannerView {
// MREC did expire and could not be shown
}
All callbacks are called on the main thread.
Placements
Appodeal SDK allows you to tag each impression with different placement. To be able to use placements, you need to create them in Appodeal Dashboard. Read more about placements.
- Swift
- Objective-C
// set placement before adding the MREC view to the view hierarchy
mrecView.placement = "placementName"
// set placement before adding the MREC view to the view hierarchy
mrecView.placement = @"placementName";
Do not use Appodeal.canShow(.MREC, forPlacement:) to check if an ad can be shown for a placement. This method is unreliable for MREC and will return false even when an ad is ready to display.
Instead, use mrec.isReady to check if the MREC view has a loaded ad before displaying it.
If the loaded ad can't be shown in a specific placement, nothing will be shown. If auto caching is enabled, the SDK will start to cache another ad, which can affect display rate.
You can configure your impression logic for each placement.
If you have no placements or call Appodeal.show with a placement that does not exist, the impression will be tagged with 'default' placement with corresponding settings applied.
Placement settings affect ONLY ad presentation, not loading or caching.
Get Predicted eCPM
This method returns the expected eCPM for the cached ad. The amount is calculated based on historical data for the current ad unit.
- Swift
- Objective-C
Appodeal.predictedEcpm(for: .MREC)
[Appodeal predictedEcpmForAdType: AppodealAdTypeMREC];
Check If Ad is Initialized
- Swift
- Objective-C
Appodeal.isInitialized(for: .MREC)
[Appodeal isInitializedForAdType: AppodealAdTypeMREC];
Returns true if MREC was initialized.
Check if Autocache Is Enabled For Ad
MREC does not support autocache.
Hide
MREC is a view. To hide MREC, remove it from superView
- Swift
- Objective-C
// MREC view
mrec.removeFromSuperview()
// MREC view
[mrec removeFromSuperview];
Check Viewability
You can always check in logs if show was tracked and your ad is visible.
You will see the following log if show was tracked successfully.
[Appodeal *.*.*] [debug] [impression] Impression <APDImpression: 0x600002953b10> succesfully tracked