iOS SDK Usage
Important: When building and testing your apps, make sure you use test ads rather than production ads. Failure to do so can lead to suspension of your account. Please see the Optional Parameters section for more info on toggling the test ads.
Banner Ads
Once the initialization of the SDK is complete, you can get and load banner ads from the EMAManager.shared
by using the following method:
Important Note: We highly recoment extending EMAViewController of the SDK for managing lifecycle of the banner.
viewController: ViewController of the banner that will be displayed.
zoneId: Banner id that will be loaded in the view.
bannerContainer: UIView that banner ad is loaded.
Optional(adStatusDelegate) self : AdStatus callback for the status of banner.
customParameters(Optional): You can pass custom key-value pairs to target Google Ad Manager campaigns.
keywords(Optional): If you are using keywords for targeting, send your parameters as string value.
EMAManager.shared.loadBannerAd(viewController, zoneId, bannerContainer)
If you set AdStatusDelegate, once loadBannerAd
method is called, one of these three will happen:
bannerStatusChanged
will be called withstatus
ofbannerManager
set toAdStatus.ready
.bannerStatusChanged
will be called withstatus
ofbannerManager
set toAdStatus.failed
.- If ads are disabled or the user is in an unfinished ad session, then
loadBannerAd
call will be ignored and nothing will happen.
As AdStatusDelegate
, you should listen to the bannerStatusChanged
events and display the ad based on its status.
func bannerStatusChanged(_ manager: DFPBannerManager) {if manager.status == .ready {self.view.addSubview(manager.banner)}}
Full Example:
class ViewController: UIViewController {@IBOutlet weak var bannerContainer: UIView!override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view.EMAManager.shared.loadBannerAd(self, "153468", bannerContainer)}}
Interstitial Ads
Load Interstitial
- Swift
- Objective-C
EmpowerInterstitialDisplayManager.shared.loadInterstitial()
Show Interstitial ad
EmpowerInterstitialDisplayManager.shared.showInterstitial()
By setting InterstitialDisplayManager
's delegate
you can listen to the status events of interstitial ads. These events are:
AdStatus.ready
interstitial is ready for display.AdStatus.failed
interstitial is failed to load an ad.AdStatus.present
interstitial is displayed and is on screen.AdStatus.willLeave
interstitial is redirecting user either to a URL or to App Store.AdStatus.used
interstitial is dismissed and needs reloading for another display.
Rewarded Ads
Rewarded ads are the ads where users have the option of interacting with in exchange for in-app rewards.
Load Rewarded Ad
- Swift
- Objective-C
EmpowerRewardedAdDisplayManager.shared.loadRewarded()
Show Rewarded Ad
EmpowerRewardedAdDisplayManager.shared.presentRewardedAd()
By setting RewardedAdDisplayManager
's delegate
you can listen to the status events of rewarded ads. These events are:
AdStatus.ready
rewarded ad is ready for display.AdStatus.failed
rewarded ad is either failed to play or failed to load.AdStatus.used
rewarded ad is being used.AdStatus.present
rewarded ad is present on the screen.AdStatus.reward
user earns the reward.