- Latest Version: iOS release notes
- Sample App: Teads iOS Sample App
This article shows you how to deliver Teads ads on your application using the AdMob adapter or Google Ad Manager (GAM) Mediation adapter.
Using CocoaPods to have Teads AdMob/GAM mediation plugin will automatically import the Teads inApp SDK framework.
Sample App on GitHub
Teads inApp SDK iOS sample App
Prerequisites
- Platform: iOS 12+
- Xcode: 15.3+
- GoogleMobileAdsSDK: >=11.2.0
Installation
Before installing the Teads AdMob adapter, you will need to integrate GoogleMobileAds 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
TeadsAdMobAdapter
in your Podfile:
pod 'TeadsAdMobAdapter', '~> 5.1'
- 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.
Swift Package Manager
SPM is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Installing from Xcode
- Add a package by selecting
File
→Add Packages…
in Xcode’s menu bar. - Search for the Teads iOS SDK using the repo's URL:
https://github.com/teads/TeadsSDK-iOS
- Next, set the Dependency Rule to be
Up to Next Major Version
and keep5.0.0 < 6.0.0
. - Choose the Teads product that you want to be installed in your app:
TeadsAdMobAdapter
- Follow the Defining a Custom Event step below to finish the integration.
Alternatively, add Teads to your Package.swift manifest
- Add it to the
dependencies
of yourPackage.swift
:
dependencies: [
.package(url: "https://github.com/teads/TeadsSDK-iOS", .upToNextMajor(from: "5.0.0"))
]
- in any target that depends on a Teads product, add it to the
dependencies
array of that target:
.target(
name: "MyTargetName",
dependencies: [
.product(name: "TeadsAdMobAdapter", package: "Teads"),
]
),
- Follow the Defining a Custom Event step below to finish the integration.
Defining a Custom Event
In order to display a Teads ad using AdMob or Google Ad Manager mediation,
you need to create a custom event.
See this article for more test PIDs serving different creative formats.
Admob
Follow the custom event documentation on the AdMob dashboard using the below values.
Name | Value |
---|---|
Class Name | TeadsAdMobAdapter.GADMAdapterTeadsBanner |
Parameter | Teads placement ID (PID) |
Google Ad Manager
Follow the custom event documentation on Google Ad Manager using the below values.
Name | Value |
---|---|
Class Name | TeadsAdMobAdapter.GADMAdapterTeadsBanner |
Parameter | Teads placement ID (PID) |
Integration
Note
Check out the sample ViewController from our iOS GitHub repository
You have the ability to pass extra parameters in order to customize third-party ad network settings. For Teads, you need to pass TeadsAdapterSettings
.
- Create an instance of
TeadsAdapterSettings
and add the settings you want. - Register it into GADRequest calling
register
import TeadsAdMobAdapter
// 1. Create AdMob view and add it to hierarchy
admobAdView = GAMBannerView(adSize: GADAdSizeFluid)
slotView.addSubview(admobAdView)
admobAdView.translatesAutoresizingMaskIntoConstraints = false
admobAdView.centerXAnchor.constraint(equalTo: slotView.centerXAnchor).isActive = true
admobAdView.centerYAnchor.constraint(equalTo: slotView.centerYAnchor).isActive = true
// 2. Attach Delegate (will include Teads events)
admobAdView.adUnitID = pid // Replace with your adunit
admobAdView.rootViewController = self
admobAdView.delegate = self
// 3. Load a new ad (this will call AdMob and Teads afterward)
let adSettings = TeadsAdapterSettings { (settings) in
settings.pageUrl("https://example.com/article1")
}
let request = GADRequest()
// 4. Register adSettings to the request
request.register(adSettings)
admobAdView.load(request)
Ad Resizing
⚠️ Warning
To resize the GAMBannerView you must use
GAMBannerView.resize()
otherwise GAM will perform a new request each time you manipulate the view frame or constraints, this is stated on the Google for Developers official documentationresize:)Known issue: the ad is flickering
- GoogleMobileAds ask TeadsAdapter to perform a new request
- ad is loading
- once ad is rendering, the ad ask for new ratio to better fit for the creative
- this ratio is beeing applied using frame/constraints update which is not allowed by GoogleMobileAds
- this UI move is not permitted by GoogleMobileAds, go back to step 1
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 GAMBannerView
that need to be resized.
var admobAdView: GAMBannerView!
@IBOutlet weak var slotView: UIView!
@IBOutlet weak var slotViewHeightConstraint: NSLayoutConstraint! // set to 0 on InterfaceBuilder
let adSettings = TeadsAdapterSettings { settings in
settings.registerAdView(admobAdView, delegate: self)
}
Simply conform to the Teads delegate TeadsMediatedAdViewDelegate
and implements the didUpdateRatio
function.
You can instantiate a new listener as below, the listener needs to be a class member field or strong referenced somewhere,
we keep internally a weak reference to it, so you are responsible to retain it and destroy it when you don't need it anymore:
func didUpdateRatio(_ adView: UIView, adRatio: TeadsAdRatio) {
let height = adRatio.calculateHeight(for: slotView.frame.width) // call calculateHeight
slotViewHeightConstraint.constant = height //update NSLayoutConstraint of the slot
admobAdView.resize(GADAdSizeFromCGSize(CGSize(width: slotView.frame.width, height: height))) //call resize on GAMBannerView
}
Warning
To resize the GAMBannerView you must use
GAMBannerView.resize()
otherwise GAM will perform a new request each time you manipulate the view frame or constraints, this is stated on the Google for Developers official documentationresize:)
Mediation settings
Find the full settings list here