This article shows you how to deliver Teads Native ads in your application using the MoPub Mediation adapter.
Using CocoaPods to have Teads Mopub mediation plugin will automatically import the Teads inApp SDK framework.
Sample App on GitHub
Teads inApp SDK iOS sample App
Prerequisites
- Platform: iOS 14.5+
- Xcode: 12.5+
- MoPub SDK: 5.13+
Installation
Before installing the Teads MoPub adapter, you will need to integrate MoPub SDK into your application.
CocoaPods
If your project is managing dependencies through CocoaPods, you just need to add this pod in your Podfile.
It will install the Teads adapter along with the Teads inApp SDK.
- Add Pod named TeadsMoPubAdapter your Podfile:
pod 'TeadsMoPubAdapter', '~> 5.0'
- Run the following to install the adapter in your project.
$ pod install --repo-update to install
- Follow the Defining a Custom Event step below to finish the integration.
Manually
- Integrate the latest version of the Teads inApp SDK to your project.
- Download the latest release of TeadsMoPubAdapter.
- Drop adapter files in your iOS project.
- Follow the Defining a Custom Event step below to finish the integration.
Defining a Custom Event
In order to display a Teads ad using MoPub, you need to create a custom event.
See this article for more test PIDs serving different creative formats.
Name | Value |
---|---|
Custom Event Class | TeadsMoPubAdapter.MPAdapterTeadsBanner |
Custom Event Class Data | {"PID": "#PID#"} |
Important
Don't forget to replace the #PID# with your Teads placement ID.
Integration
Important
MPAdView automatically refreshes an ad unit at a time interval specified via the MoPub web interface. You need to disable automatic refreshing content
adView.stopAutomaticallyRefreshingContents()
You have the ability to pass extra parameters in order to customize third-party ad network settings. For Teads, you need to pass TeadsAdapterSettings
.
- Register your
TeadsAdapterSettings
into MPAdView usingregister
.
let settings = TeadsAdapterSettings { settings in
settings.pageUrl("https://example.com/article1")
}
let mopubAdView = MPAdView(adUnitId: MOPUB_AD_UNIT_ID)
mopubAdView.delegate = self
mopubAdView.register(teadsAdSettings: settings)
mopubAdView.stopAutomaticallyRefreshingContents() //disabling auto refresh content
mopubAdView.loadAd(withMaxAdSize: kMPPresetMaxAdSizeMatchFrame)
Ad Resizing
The code below must be implemented to enable the resizing of the mediated ad slot making possible the rendering of square and vertical creatives.
Register to ad resizing through TeadsAdapterSettings
by providing your delegate class and the MPAdView
that need to be resized
var mopubAdView: MPAdView!
@IBOutlet weak var slotHeight: NSLayoutConstraint! // set to 0 on InterfaceBuilder
let adSettings = TeadsAdapterSettings { settings in
settings.registerAdView(mopubAdView, delegate: self)
}
Simply conform to the Teads delegate TeadsMediatedAdViewDelegate
and implements the didUpdateRatio
function.
You can implement delegate as below, we keep internally a weak reference to it, so it's not retained when you don't need it anymore:
func didUpdateRatio(_ adView: UIView, adRatio: TeadsAdRatio) {
let height = adRatio.calculateHeight(for: slotView.frame.width) // call calculateHeight
slotHeight.constant = height //update NSLayoutConstraint of the slot
}
Mediation settings
Find the full settings list here