Search code examples
swiftxcodeadmobbanner-ads

Why isn't my AdMob banner ad being displayed on the screen?


I am trying to use AdMob to make a banner ad but nothing is being displayed on my screen. For right now, I just want the ad to be displayed at the bottom of a plain white screen. This is the code that I am using, but it is only displaying a blank screen without an ad. Why is this happening?

    var bannerView: GADBannerView!
    override func viewDidLoad() {

        bannerView = GADBannerView(adSize: kGADAdSizeBanner)
        bannerView.delegate = self
        bannerView.adUnitID = AdMob.bannerid
        bannerView.rootViewController = self
        addBannerViewToView(bannerView)
        bannerView.load(GADRequest())

    }
//MARK: - AdMob
    
    func adViewDidReceiveAd(_ bannerView: GADBannerView) {
      bannerView.alpha = 0
      UIView.animate(withDuration: 1, animations: {
        bannerView.alpha = 1
      })
    }
    
    func addBannerViewToView(_ bannerView: GADBannerView) {
        bannerView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(bannerView)
        view.addConstraints(
          [NSLayoutConstraint(item: bannerView,
                              attribute: .bottom,
                              relatedBy: .equal,
                              toItem: view.safeAreaLayoutGuide,
                              attribute: .bottom,
                              multiplier: 1,
                              constant: 0),
           NSLayoutConstraint(item: bannerView,
                              attribute: .centerX,
                              relatedBy: .equal,
                              toItem: view,
                              attribute: .centerX,
                              multiplier: 1,
                              constant: 0)
          ])
       }
    
}

I am getting the following messages but the app is not crashing:

2021-01-01 18:15:58.117046-0600 App[4837:919022] WF: === Starting WebFilter logging for process App

2021-01-01 18:15:58.117101-0600 App[4837:919022] WF: _userSettingsForUser mobile: {
    filterBlacklist =     (
    );
    filterWhitelist =     (
    );
    restrictWeb = 1;
    useContentFilter = 0;
    useContentFilterOverrides = 0;
    whitelistEnabled = 0;
}

2021-01-01 18:15:58.117140-0600 App[4837:919022] WF: _WebFilterIsActive returning: NO

2021-01-01 18:15:58.238219-0600 App[4837:919224] 7.3.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled

2021-01-01 18:15:58.238983-0600 App[4837:919224] 7.3.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist

What do I need to change?


Solution

  • This problem has been resolved. I had not entered my billing information on my Admob account, so my account verification had not been processed yet. If you are having the same issue, I recommend:

    1. registering your device as a test device
    2. Checking your code with a test ad

    If the test ad appears, make sure that you have taken the required measures to get your account verified.