MREC is 300x250 banner. This type can be useful if the application has a large free area for placing a banner in the interface.

1. Manual Caching

MREC does not support autocache.

To cache MREC use:

// MREC view
mrec.loadAd()
Read more on manual caching in our FAQ.

2. Check if MREC is loaded

// MREC view
mrec.isReady 

3. Display MREC

Class AppodealMRECView is a subclass of AppodealBannerViewAppodealMRECView has size 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")
  }
}

4. Use MREC callbacks

Callbacks are used to track different lifecycle events of an ad, e.g., when a MREC has successfully loaded or is about to appear. To get them, you need to set the delegate as follows:

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

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

All callbacks are called on the main thread.

5. Hide MREC

MREC is view, for hiding MREC remove MREC from superView

// MREC view
mrec.removeFromSuperview()   

6. MREC Placements

Appodeal SDK allows you to tag each impression with different placement. For using placements you need to create placements in Appodeal Dashboard.  Read more  about placements.

Appodeal.showAd(.MREC, forPlacement: placement, rootViewController: self)
If the loaded ad can’t be shown for a specific placement, nothing will be shown. If auto caching is enabled, sdk will start to cache another ad, which can affect display rate. To save the loaded ad for future use (for instance, for another placement) check if the ad can be shown before calling show method:


Appodeal.canShow(.MREC, forPlacement: placement)
You can configure your impression logic for each placement.

If you have no placements, or call  Appodeal.show  with placement that do not exist, the impression will be tagged with 'default' placement and its settings will be applied.

Important!

Placement settings affect ONLY ad presentation, not loading or caching.

7. Get Predicted eCPM

This method return expected eCPM for cached ad. Amount is calculated based on historical data for the current ad unit.

Appodeal.predictedEcpm(for: .MREC)

8. Check if MREC was initialized

Appodeal.isInitialized(for: .MREC)

Returns true, if MREC was initialized.

9. Check if autocache is enabled for MREC

MREC does not support autocache.