Skip to content

Commit b232024

Browse files
author
Hugo Gresse
committed
Change event name + add comment
1 parent b81edd8 commit b232024

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

TeadsDemoApp/Controllers/adMobController/AdMobController.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ import UIKit
1111

1212
class AdMobController: UIViewController, GADBannerViewDelegate {
1313

14+
// FIXME This ids should be replaced by your own AdMob application and ad block/unit ids
15+
let ADMOB_APP_ID = "ca-app-pub-3570580224725271~8055914490"
16+
let ADMOB_AD_UNIT_ID = "ca-app-pub-3570580224725271/5615499706"
17+
1418
var bannerView: GADBannerView!
1519
@IBOutlet weak var slotView: UIView!
1620

1721
override func viewDidLoad() {
1822
super.viewDidLoad()
1923

2024
// 1. Init AdMob (could be done in your Application class)
21-
GADMobileAds.configure(withApplicationID: "ca-app-pub-3570580224725271~8055914490")
25+
GADMobileAds.configure(withApplicationID: ADMOB_APP_ID)
2226

2327
// 2. Create AdMob view and add it to hierarchy
2428
self.bannerView = GADBannerView(adSize: kGADAdSizeMediumRectangle)
@@ -29,7 +33,7 @@ class AdMobController: UIViewController, GADBannerViewDelegate {
2933
self.bannerView.centerYAnchor.constraint(equalTo: self.slotView.centerYAnchor)])
3034

3135
// 3. Attach Delegate (will include Teads events)
32-
bannerView.adUnitID = "ca-app-pub-3570580224725271/5615499706"
36+
bannerView.adUnitID = ADMOB_AD_UNIT_ID
3337
bannerView.rootViewController = self
3438
bannerView.delegate = self
3539

@@ -45,7 +49,7 @@ class AdMobController: UIViewController, GADBannerViewDelegate {
4549
// The article url if you are a news publisher
4650
teadsExtras.pageUrl = "http://page.com/article1"
4751

48-
request.register(teadsExtras.getCustomEventExtras(forCustomEventLabel: "__custom_event_label__"))
52+
request.register(teadsExtras.getCustomEventExtras(forCustomEventLabel: "Teads"))
4953

5054
bannerView.load(request)
5155
}
@@ -54,11 +58,14 @@ class AdMobController: UIViewController, GADBannerViewDelegate {
5458

5559
/// Tells the delegate an ad request loaded an ad.
5660
func adViewDidReceiveAd(_ bannerView: GADBannerView) {
61+
// reset the size to "kGADAdSizeMediumRectangle" if a didFailToReceiveAdWithError was triggered before.
62+
NSLayoutConstraint.activate([self.slotView.heightAnchor.constraint(equalToConstant: 250)])
5763
}
5864

5965
/// Tells the delegate an ad request failed.
6066
func adView(_ bannerView: GADBannerView,
6167
didFailToReceiveAdWithError error: GADRequestError) {
68+
NSLayoutConstraint.activate([self.slotView.heightAnchor.constraint(equalToConstant: 0)])
6269
print("adView:didFailToReceiveAdWithError: \(error.localizedDescription)")
6370
}
6471

0 commit comments

Comments
 (0)