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:
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:
- Navigation Bar
- Safe Zone begins
- A simple UIView to contain the banner
- TableView
- Safe Zone ends
- 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:
- Align trailing to: Safe Area
- Align leading to: Safe Area
- Height equals: 50
- Bottom Space to: Table View
- Align Top to: Safe Area