Skip to main content
Version:

MREC

View-Based Ad Type

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​

Important

For MREC ads, you must use the mrec.isReady property to check if an ad is loaded and ready to display.

// 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:

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")
}
}

Manual Caching​

MREC does not support autocache.

To cache MREC use:

// 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:

//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:

// 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) {}

note

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.

// set placement before adding the MREC view to the view hierarchy
mrecView.placement = "placementName"

Important for MREC

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.

Important!

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.

Appodeal.predictedEcpm(for: .MREC)

Check If Ad is Initialized​

Appodeal.isInitialized(for: .MREC)

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

// 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