iOS
The Ezoic Ads SDK for iOS lets you display banner ads in native iOS apps. The SDK initializes Ezoic configuration, Prebid header bidding, Google Ad Manager, and consent handling from one integration point.
Requirements 🔗
- iOS 14.0 or higher
- Xcode 15.0 or higher
- Swift 5.9 or higher
- Google Mobile Ads application ID
Installation 🔗
Add the SDK with Swift Package Manager.
In Xcode, go to File > Add Package Dependencies and enter:
https://github.com/ezoic/ezoic-swift-sdk-dist.git
Select Exact Version and choose 1.0.0-rc4 or the release version provided by Ezoic. Pre-release versions are not picked up by Up to Next Major Version rules — pin them exactly.
Or add the package to Package.swift using the release version provided for your app:
dependencies: [
.package(url: "https://github.com/ezoic/ezoic-swift-sdk-dist.git", exact: "1.0.0-rc4")
]
The SDK is distributed as a pre-built EzoicAdsSDK.xcframework attached to each GitHub release. When you add the package, Swift Package Manager also resolves the Prebid Mobile and Google Mobile Ads SDKs as transitive dependencies — you do not need to add them yourself.
Initialize the SDK 🔗
Initialize the SDK in your AppDelegate or app startup flow before loading ads.
import EzoicAdsSDK
let config = EzoicConfiguration(
domain: "example.com",
debugEnabled: false,
testMode: false
)
EzoicAds.shared.initialize(with: config) { result in
switch result {
case .success:
print("Ezoic SDK initialized")
case .failure(let error):
print("Ezoic initialization failed: \(error)")
}
}
domain must match the domain configured for your site in Ezoic. Authentication is handled by the app's bundle identifier and the configured domain — there is no client-side API key.
For apps using async/await on iOS 15 or higher:
try await EzoicAds.shared.initialize(with: config)
Add a Banner Ad 🔗
Create an EzoicBannerView, add it to your view hierarchy, and call loadAd() after the SDK is initialized.
import EzoicAdsSDK
import UIKit
class ViewController: UIViewController {
private var bannerView: EzoicBannerView?
override func viewDidLoad() {
super.viewDidLoad()
let adView = EzoicBannerView(adUnitIdentifier: 12345)
adView.delegate = self
adView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(adView)
NSLayoutConstraint.activate([
adView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
adView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
adView.widthAnchor.constraint(equalToConstant: EzoicBannerSize.banner.width),
adView.heightAnchor.constraint(equalToConstant: EzoicBannerSize.banner.height)
])
bannerView = adView
adView.loadAd()
}
}
extension ViewController: EzoicBannerViewDelegate {
func bannerViewDidLoad(_ bannerView: EzoicBannerView) {
print("Banner loaded")
}
func bannerView(_ bannerView: EzoicBannerView, didFailToLoadWithError error: EzoicError) {
print("Banner failed: \(error)")
}
}
Replace 12345 with your numeric Ezoic ad unit identifier. The SDK fetches the Google Ad Manager ad unit, Prebid configuration, supported sizes, targeting values, and refresh interval from Ezoic servers.
Banner Sizes 🔗
You can load ads with an adaptive default size, a typed size, one size string, or a list of size strings.
adView.loadAd()
adView.loadAd(size: EzoicBannerSize.mediumRectangle)
adView.loadAd(size: "300x250")
adView.loadAd(sizes: ["300x250", "320x50"])
Common sizes include:
EzoicBannerSize.banner: 320x50EzoicBannerSize.largeBanner: 320x100EzoicBannerSize.mediumRectangle: 300x250EzoicBannerSize.fullBanner: 468x60EzoicBannerSize.leaderboard: 728x90EzoicBannerSize.custom(width:height:): custom dimensions
You can also use the adaptive size for the current screen width:
let adaptiveSize = EzoicBannerSize.adaptiveSize
Info.plist 🔗
Add your Google Mobile Ads application ID to Info.plist:
In most Ezoic mobile app integrations, this app ID is provided by Ezoic and can be found in your Ezoic dashboard. Use the value assigned to your app unless your Ezoic representative gives you a different Google Mobile Ads application ID.
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-XXXXXXXXXXXXXXXX~XXXXXXXXXX</string>
If your app uses App Tracking Transparency, include a tracking usage description:
<key>NSUserTrackingUsageDescription</key>
<string>This app uses tracking to deliver personalized ads.</string>
Add any SKAdNetwork identifiers required by your ad partners.
Privacy and Consent 🔗
The SDK can automatically read consent signals from UserDefaults when they are set by a consent management platform.
- TCF v2 consent is read from
IABTCF_*keys. - GPP consent is read from
IABGPP_*keys. - US Privacy consent is read from the standard IAB privacy key.
You can also set consent manually:
EzoicAds.shared.setGDPRConsent(
applies: true,
consentString: "TCF_CONSENT_STRING"
)
EzoicAds.shared.setGPPConsent(
gppString: "GPP_STRING",
sectionIds: "7"
)
EzoicAds.shared.setSubjectToCOPPA(true)
Pageview Tracking 🔗
The SDK automatically tracks view controller navigation after initialization.
You can also track a pageview manually when a user navigates to a new screen or content view:
EzoicAds.shared.trackPageview { success in
print("Pageview tracked: \(success)")
}
For apps using async/await on iOS 15 or higher:
let success = await EzoicAds.shared.trackPageview()
Troubleshooting 🔗
SDK Not Initializing 🔗
- Confirm the configured
domainmatches your Ezoic dashboard. - Confirm the app has network access.
- Enable
debugEnabled: trueand review SDK logs in the Xcode console.
Ads Not Loading 🔗
- Initialize the SDK before calling
loadAd(). - Confirm the Ezoic ad unit identifier is configured in Ezoic.
- Confirm the Google Mobile Ads application ID is present in
Info.plist. - Check consent configuration if traffic is subject to privacy regulations.