iOS应用中Google Mobile Ads SDK激励视频广告加载失败求助
Hey there, let’s break down why you’re seeing those frequent Request Error: No ad to show (Code=1) errors and how to fix them. I’ll walk through potential issues in your code and broader AdMob setup, plus actionable fixes.
First: Rule Out Testing Environment Issues
If you’re testing on a physical device with your live ad unit IDs, that’s likely part of the problem. AdMob intentionally limits fill rate for live ads on test devices to prevent accidental clicks and charges. Here’s how to fix this immediately:
- Use AdMob’s official test ad unit IDs:
- Rewarded Video:
ca-app-pub-3940256099942544/1712485313 - Banner:
ca-app-pub-3940256099942544/2934735716
- Rewarded Video:
- Add your test device ID to the request configuration so AdMob recognizes it as a test device:
func getRequest() -> GADRequest { let request = GADRequest() // Replace with your device's advertising identifier (find it in Xcode's console logs) GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = ["YOUR_TEST_DEVICE_ID"] return request }
This should give you 100% fill rate for testing.
Fix Your Ad Loading Logic & Missing Delegates
Looking at your code, there are a few gaps that could contribute to failed loads:
1. Missing Error Handling for Failed Loads
You haven’t implemented the rewardBasedVideoAd(_:didFailToLoadWithError:) delegate method. This means you’re blind to why loads are failing (e.g., network issues, expired ads, or actual fill rate problems). Add this to your ViewController:
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didFailToLoadWithError error: Error) { print("Rewarded video failed to load: \(error.localizedDescription)") // Add a retry delay to avoid spamming AdMob's servers DispatchQueue.main.asyncAfter(deadline: .now() + 3) { GameViewController.loadVideo() } }
For banners, conform to GADBannerViewDelegate and implement bannerView(_:didFailToReceiveAdWithError:) similarly.
2. Static BannerView May Cause Lifecycle Issues
Using a static GameViewController.bannerView can lead to problems if your ViewController is destroyed and recreated (e.g., during navigation). Switch it to an instance variable instead:
var bannerView: GADBannerView? override func viewDidLoad() { super.viewDidLoad() // ... other code if bannerView == nil { bannerView = GADBannerView(adSize: kGADAdSizeBanner) bannerView?.adUnitID = bannerId bannerView?.rootViewController = self bannerView?.delegate = self // Add this to handle banner errors/loads bannerView?.load(getRequest()) bannerView?.isHidden = true addBannerViewToView(bannerView!) } }
3. Avoid Overloading Ad Requests
Your loadVideo() method checks isReady before loading, but ads can expire even if isReady returns true. Additionally, don’t call load() immediately after a failed load without a delay—AdMob may rate-limit your requests.
Improve Fill Rate for Live Ads
If you’re seeing low fill rate with live ad units, here are longer-term fixes:
- Check AdMob Console: Verify your ad units are correctly linked to your app ID, and there are no policy violations or account restrictions.
- Build User Volume: New apps often have low fill rate because AdMob needs time to learn your audience. Focus on growing active users to attract more advertisers.
- Use Ad Mediation: Integrate other ad networks (e.g., Unity Ads, AdColony) via AdMob Mediation. This lets you fall back to other networks when AdMob has no ads available.
- Optimize Ad Targeting: Add keywords or user demographics to your ad requests to help AdMob match better ads:
func getRequest() -> GADRequest { let request = GADRequest() request.keywords = ["gaming", "mobile games", "puzzle"] // Match your app's genre return request }
Final Checks
- Make sure you’re using the latest version of the Google Mobile Ads SDK. Outdated versions can cause compatibility issues.
- Test your app in different regions (if your audience is global) to see if fill rate varies by location.
内容的提问来源于stack exchange,提问作者Pablo

