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.
Do NOT use Appodeal.isLoaded(.MREC) or Appodeal.canShow(.MREC) as they are unreliable for MREC and will return false even when an ad is loaded and ready to show.
- Swift
- Objective-C
// MREC view - CORRECT way to check if loaded
mrec.isReady
// ❌ INCORRECT - These methods are unreliable for MREC:
// Appodeal.isLoaded(.MREC) // Will return false even when loaded
// Appodeal.canShow(.MREC) // Will return false even when loaded
// MREC view - CORRECT way to check if loaded
mrec.isReady;
// ❌ INCORRECT - These methods are unreliable for MREC:
// [Appodeal isLoaded:AppodealAdTypeMREC]; // Will return false even when loaded
// [Appodeal canShow:AppodealAdTypeMREC]; // Will return false even when loaded
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] initWithRootViewController: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 {
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);
}
- (void)bannerViewDidRefresh:(APDBannerView *)bannerView {
NSLog(@"Banner %@ did refresh ", bannerView);
}
@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
Appodeal.setBannerDelegate(self)
//set delegate
[Appodeal setBannerDelegate: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
// banner was loaded (precache flag shows if the loaded ad is precache)
func bannerDidLoadAdIsPrecache(_ precache: Bool) {}
// banner was shown
func bannerDidShow() {}
// banner failed to load
func bannerDidFailToLoadAd() {}
// banner was clicked
func bannerDidClick() {}
// banner did expire and could not be shown
func bannerDidExpired() {}
- (void)bannerDidLoadAdIsPrecache:(BOOL)precache {
// banner was loaded (precache flag shows if the loaded ad is precache)
}
- (void)bannerDidShow {
// banner was shown
}
- (void)bannerDidFailToLoadAd {
// banner failed to load
}
- (void)bannerDidClick {
// banner was clicked
}
- (void)bannerDidExpired {
// banner 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
Appodeal.showAd(.MREC, forPlacement: placement, rootViewController: self)
[Appodeal showAd:AppodealShowStyleMREC forPlacement:placement rootViewController:self];
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 isInitalizedForAdType: 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