You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS Swift应用首页启动时AdMob Banner不显示问题求助

Troubleshooting AdMob Banner Not Showing on iOS App First Launch (Swift)

Hey there! I know it’s frustrating when your AdMob Banner won’t show up on the home screen even after you’ve double-checked your code logic. Let’s walk through the most likely fixes to get it displaying on first launch:

  • Verify AdMob Account & Unit Setup

    • Double-check that you’ve created a valid Banner ad unit ID in your AdMob dashboard—typos here are super common! For testing, use AdMob’s official test ID: ca-app-pub-3940256099942544/2934735716 (this guarantees ads will load, ruling out real-world fill issues).
    • Ensure your app’s GADApplicationIdentifier is correctly added to Info.plist under the GADApplicationIdentifier key. Missing this will break all AdMob functionality.
  • Check Layout Constraints

    • Even if your code is right, incorrect constraints might hide the banner off-screen. Make sure you’re pinning the banner to the top of the safe area with leading/trailing constraints that match the screen width:
      bannerView.translatesAutoresizingMaskIntoConstraints = false
      NSLayoutConstraint.activate([
          bannerView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
          bannerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
          bannerView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
      ])
      
    • Confirm the banner uses a valid AdMob ad size (e.g., GADAdSizeBanner for standard 50pt height on iPhones). Using a custom size that’s too small might prevent ads from loading.
  • Validate Initialization & Loading Timing

    • Initialize AdMob early in your app’s lifecycle—add this in AppDelegate’s didFinishLaunchingWithOptions:
      GADMobileAds.sharedInstance().start(completionHandler: nil)
      
    • Load the banner in viewDidLoad or viewWillAppear of your home view controller, and make sure you’ve set the rootViewController property on the GADBannerView (this is required for ad interactions).
  • Handle Privacy Requirements (iOS 14+)

    • For iOS 14 and above, you need to include the NSUserTrackingUsageDescription key in Info.plist to explain why you need user tracking. Without this, AdMob can’t access the IDFA, which reduces ad fill rates.
    • Don’t forget to request user tracking authorization using the App Tracking Transparency framework before loading ads:
      import AppTrackingTransparency
      import AdSupport
      
      func requestTrackingAuthorization() {
          ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
              // Load ads after authorization is granted (or denied—ads might still load but with limited targeting)
              DispatchQueue.main.async {
                  self.bannerView.load(GADRequest())
              }
          })
      }
      
  • Check Xcode Console for Errors

    • This is the most critical step! Launch your app and look for AdMob-related logs in the Xcode console. Common errors include:
      • Ad failed to load: Request Error: No ad to show. (No fill for your ad unit—use the test ID to confirm)
      • GADRequestError Code: 2 (Invalid ad unit ID or app ID)
      • GADRequestError Code: 3 (Network issue or ad filtering)
    • Implement the GADBannerViewDelegate to catch failures explicitly:
      func adViewDidFailToReceiveAdWithError(_ bannerView: GADBannerView, error: Error) {
          print("Ad load failed: \(error.localizedDescription)")
          if let gadError = error as? GADRequestError {
              print("AdMob Error Code: \(gadError.code)")
          }
      }
      

Start with testing the official AdMob test ID—if that loads, the issue is with your real ad unit (e.g., pending approval, low fill rate). If the test ID still doesn’t show, dive into constraints, initialization timing, and privacy settings next.

内容的提问来源于stack exchange,提问作者Christoffer Karlsson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:08:38