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:
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:
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.