0

i am adding GoogleMobileAds in Swift project and i have done all the steps successfully which is provided in doc and ads are showing in my app just issue is that when i push to other ViewController than ads banner view still show on top of ViewController i just want ads bannerview to main screen of tabbar not detail here is my code

 var bannerView: GADBannerView!
    bannerView = GADBannerView(adSize: kGADAdSizeBanner)
    addBannerViewToView(bannerView)
    bannerView.adUnitID = "here i add my adUnitID"
    bannerView.rootViewController = self
    bannerView.load(GADRequest())
    
    func addBannerViewToView(_ bannerView: GADBannerView){
                bannerView.translatesAutoresizingMaskIntoConstraints = false
                view.addSubview(bannerView)
                view.addConstraints([
                    NSLayoutConstraint(item: bannerView,
                                       attribute: .bottom,
                                       relatedBy: .equal,
                                       toItem: tabBar,
                                       attribute: .top,
                                       multiplier: 1,
                                       constant: 0),
                    NSLayoutConstraint(item: bannerView,
                                       attribute: NSLayoutConstraint.Attribute.centerX,
                                       relatedBy: .equal,
                                       toItem: view,
                                       attribute: .centerX,
                                       multiplier: 1,
                                       constant: 0)
                ])
            }

here is with this code ads loaded successfully but when push to new view controller than bannerview shows on that screen can any one have idea about this?

posah
  • 1
  • 2

1 Answers1

0

I wouldn't say this is an "answer" per say, but since no one has responded yet (and I am unable to comment since I have <50 reputation points), I'll just throw this thought out there. Since GADBannerView is a subclass of UIView, just think of it as a regular view. You must be adding this view to the pushed view controller somehow without knowing it, otherwise it wouldn't be able to display the ad.

Eric33187
  • 1,006
  • 7
  • 13