iOS SDK Configuration

Initializing the SDK

SDK Initialization

Initialize the SDK as early as possible in your app lifecycle, preferably in AppDelegate.

Basic Initialization

import EmpowerMobileAds
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize the SDK with your app identifier
EMAManager.shared.initAd("your_app_identifier")
return true
}
}

Initialization with Options

// Initialize with test mode enabled
EMAManager.shared.initAd("your_app_identifier", "1.0", true)
// Set log level for debugging
EMASettings.shared.logLevel = .all
// Set root view controller (required for interstitials/rewarded)
EMASettings.shared.rootViewController = window?.rootViewController

app_identifier: Your app idenfier which will be provided by us.

Configuration Options

SettingDescriptionDefault
logLevelLog verbosity (.none, .error, .all).none
testModeEnable test adsfalse
isAdsDisabledDisable all ads (e.g., for premium users)false
isAdsNonPersonalizedRequest non-personalized adsfalse

Log Levels

LevelDescription
ALLLogs all messages including debug information
DEFAULTLogs general information and errors
WARNINGLogs warnings and errors only
ERRORLogs errors only
NONEDisables all logging

Listening for SDK Ready State (Optional)

If you need to know exactly when the SDK is ready (for analytics, UI updates, etc.), you can implement AppViewDelegate:

import EmpowerMobileAds
@main
class AppDelegate: UIResponder, UIApplicationDelegate, AppViewDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Register as delegate before initialization
EMAManager.shared.appViewDelegates.append(self)
// Initialize the SDK
EMAManager.shared.initAd("YOUR_APP_AD_IDENTIFIER")
return true
}
// MARK: - AppViewDelegate
func appViewCompleted() {
// SDK is initialized and ready to load ads
// Use this for analytics or UI updates
print("Empower SDK is ready")
}
func appViewFailed() {
// SDK initialization failed
// Handle the error appropriately
print("Empower SDK initialization failed")
}
}

Note: This delegate is optional. Since all ad types automatically queue, you don't need to wait for appViewCompleted() before loading ads.


GDPR Compliance

For users in regions requiring GDPR compliance, enable non-personalized ads:

// Option 1: Set before initialization
EMASettings.shared.isAdsNonPersonalized = true
EMAManager.shared.initAd("YOUR_APP_AD_IDENTIFIER")
// Option 2: At runtime based on user consent
EMASettings.shared.isAdsNonPersonalized = !userHasGivenConsent

App Tracking Transparency (iOS 14+)

For iOS 14 and later, you should request App Tracking Transparency permission before initializing the SDK:

import AppTrackingTransparency
import EmpowerMobileAds
func requestTrackingPermissionAndInitSDK() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
DispatchQueue.main.async {
switch status {
case .authorized:
// User granted permission - personalized ads enabled
EMASettings.shared.isAdsNonPersonalized = false
case .denied, .restricted:
// User denied permission - use non-personalized ads
EMASettings.shared.isAdsNonPersonalized = true
case .notDetermined:
// Permission not yet requested
EMASettings.shared.isAdsNonPersonalized = true
@unknown default:
EMASettings.shared.isAdsNonPersonalized = true
}
// Initialize SDK after permission response
EMAManager.shared.initAd("YOUR_APP_AD_IDENTIFIER")
}
}
} else {
// iOS 13 and earlier - no ATT required
EMAManager.shared.initAd("YOUR_APP_AD_IDENTIFIER")
}
}

Don't forget to add the NSUserTrackingUsageDescription key to your Info.plist:

<key>NSUserTrackingUsageDescription</key>
<string>This app uses your data to provide personalized ads.</string>

Lifecycle Management

The SDK automatically manages ad lifecycle based on your app's state. You can check the SDK status:

// Check if SDK is initialized
if EMAManager.shared.isSdkInitialized() {
// Safe to load ads
}
// Check if ad configuration is ready
if EMAManager.shared.isAdsReadyForDisplay {
// Ad configuration has been received from server
}
// Check if ads are disabled (premium user, VoiceOver, etc.)
if EMAManager.shared.isDisabled {
// Ads will not be shown
}

Background/Foreground Handling

The SDK automatically handles app state transitions. For custom behavior, you can hook into these events:

// In AppDelegate or SceneDelegate
func applicationDidEnterBackground(_ application: UIApplication) {
// SDK automatically pauses all ad refresh timers
// No action required
}
func applicationWillEnterForeground(_ application: UIApplication) {
// SDK automatically resumes ad refresh timers
// If app was in background for extended period,
// SDK will refresh ad configuration automatically
}

Disabling Ads for Premium Users

// Disable all ads for premium users
func userPurchasedPremium() {
EMASettings.shared.isAdsDisabled = true
// Destroy any currently loaded ads
// (they will automatically stop showing)
}
// Re-enable ads if subscription expires
func premiumSubscriptionExpired() {
EMASettings.shared.isAdsDisabled = false
}