简体   繁体   中英

set google ad bannerview to tabbr controller but when i push to detail view than still ads showing

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM