iosswiftgadbannerview

AdMob banner appears under home indicator in the first load and from time to time


When ViewControllers loaded in my app for the first time, AdMob banners do not appear in their dedicated superviews, but instead banners appear under the home indicator, as shown in the screenshot:

Banner appears under "home indicator" on iPhone 11

I have noticed that this does not happen only in the first load, but also from time to time.

When I go forward and back around scenes (ViewControllers), sometimes every banner appears in its dedicated superview as it should be, sometimes they don't.

Banners's dedicated superviews' top constraints are 0 to safe zone. So they should appear right under the navigation bar. The views are designed in the following order from top to bottom:

  1. Navigation Bar
  2. Safe Zone begins
  3. A simple UIView to contain the banner
  4. TableView
  5. Safe Zone ends
  6. Home Indicator

Related code:

override func viewWillAppear(_ animated: Bool) {
    setBanner()
}

func setBanner() {
    banner.delegate = self
    banner.rootViewController = self
    banner.load(GADRequest())
    GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers =
    [ "kGADSimulatorID" ]        
    bannerContainerView.addSubview(banner)
}

I put the setBanner() in func viewDidLoad() instead of viewWillAppear(), but nothing changed.

I tested and noticed this behavior on both iOS simulator and on physical device.

This problem does not occur when I test it on iPhone 8, as it does not have a visible space under safe zone.

I guess that banner loads before its superview is available somehow, but I am not sure.

Update: Contraints of the view which contains the banner:


Solution

  • I realized that this problem caused not by the constraints of the UIView which contains the banner, but by the constraints of the banner which were set in the code (by view.addConstraint()). I have disabled such constraints and problem was simply solved.