iOS
The Ezoic Ads SDK for iOS lets you display banner ads in native iOS apps. The SDK initializes Ezoic configuration, Prebid, 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.git
Select the released version or branch provided by Ezoic.
Or add the package to Package.swift using the branch or version provided for your app:
dependencies: [
.package(url: "https://github.com/ezoic/ezoic-swift-sdk.git", branch: "master")
]
Initialize the SDK 🔗
Initialize the SDK in your AppDelegate or app startup flow before loading ads.
import EzoicAdsSDK
let config = EzoicConfiguration(
apiKey: "your-api-key",
siteId: "your-site-id",
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)")
}
}
The SDK uses your API key and site ID to fetch remote configuration from Ezoic.
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 Ezoic ad unit identifier. The SDK fetches the Google Ad Manager ad unit, Prebid configuration, supported sizes, and refresh interval from Ezoic servers.
Banner Sizes 🔗
Common banner 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 API key and site ID are configured for your app.
- Confirm the app has network access.
- Enable
debugEnabled: trueand review SDK logs.
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.