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@mainclass AppDelegate: UIResponder, UIApplicationDelegate {func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Initialize the SDK with your app identifierEMAManager.shared.initAd("your_app_identifier")return true}}
Initialization with Options
// Initialize with test mode enabledEMAManager.shared.initAd("your_app_identifier", "1.0", true)// Set log level for debuggingEMASettings.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
| Setting | Description | Default |
|---|---|---|
logLevel | Log verbosity (.none, .error, .all) | .none |
testMode | Enable test ads | false |
isAdsDisabled | Disable all ads (e.g., for premium users) | false |
isAdsNonPersonalized | Request non-personalized ads | false |
Log Levels
| Level | Description |
|---|---|
ALL | Logs all messages including debug information |
DEFAULT | Logs general information and errors |
WARNING | Logs warnings and errors only |
ERROR | Logs errors only |
NONE | Disables 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@mainclass AppDelegate: UIResponder, UIApplicationDelegate, AppViewDelegate {func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Register as delegate before initializationEMAManager.shared.appViewDelegates.append(self)// Initialize the SDKEMAManager.shared.initAd("YOUR_APP_AD_IDENTIFIER")return true}// MARK: - AppViewDelegatefunc appViewCompleted() {// SDK is initialized and ready to load ads// Use this for analytics or UI updatesprint("Empower SDK is ready")}func appViewFailed() {// SDK initialization failed// Handle the error appropriatelyprint("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 initializationEMASettings.shared.isAdsNonPersonalized = trueEMAManager.shared.initAd("YOUR_APP_AD_IDENTIFIER")// Option 2: At runtime based on user consentEMASettings.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 AppTrackingTransparencyimport EmpowerMobileAdsfunc requestTrackingPermissionAndInitSDK() {if #available(iOS 14, *) {ATTrackingManager.requestTrackingAuthorization { status inDispatchQueue.main.async {switch status {case .authorized:// User granted permission - personalized ads enabledEMASettings.shared.isAdsNonPersonalized = falsecase .denied, .restricted:// User denied permission - use non-personalized adsEMASettings.shared.isAdsNonPersonalized = truecase .notDetermined:// Permission not yet requestedEMASettings.shared.isAdsNonPersonalized = true@unknown default:EMASettings.shared.isAdsNonPersonalized = true}// Initialize SDK after permission responseEMAManager.shared.initAd("YOUR_APP_AD_IDENTIFIER")}}} else {// iOS 13 and earlier - no ATT requiredEMAManager.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 initializedif EMAManager.shared.isSdkInitialized() {// Safe to load ads}// Check if ad configuration is readyif 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 SceneDelegatefunc 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 usersfunc userPurchasedPremium() {EMASettings.shared.isAdsDisabled = true// Destroy any currently loaded ads// (they will automatically stop showing)}// Re-enable ads if subscription expiresfunc premiumSubscriptionExpired() {EMASettings.shared.isAdsDisabled = false}