简体   繁体   English

插页式 iAd 并非每次都显示

[英]Interstitial iAd doesn't show every time

I am implementing interstitial ads in my iPhone app.我正在我的 iPhone 应用程序中实施插页式广告。 I call the same block of code:我调用相同的代码块:

showInterstitialAds = true
self.interstitialAd.delegate = self
self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Automatic
println(interstitialAd)
requestingAd = true

However, an interstitial ad is not shown every time - maybe once every 5 or 10 plays.但是,插页式广告并非每次都显示 - 可能每播放 5 或 10 次。 Why is this?为什么是这样?

Also, how can I check if an interstitial ad will not be shown, so that I can display a banner ad instead?另外,如何检查是否不会显示插页式广告,以便我可以显示横幅广告?

The iAd platform serves ads to apps from an inventory of ads. iAd 平台从广告库存中向应用程序投放广告。 The inventory available to any individual app depends on a lot of different factors, including the category of your app, whether your app cancels advertisements regularly, pricing and lots of other commercial factors that only Apple knows.任何单个应用程序可用的库存取决于许多不同的因素,包括应用程序的类别、应用程序是否定期取消广告、定价以及许多其他只有 Apple 知道的商业因素。 Your app needs to handle the situation where you are not receiving an ad - as this will be a normal situation.您的应用需要处理您没有收到广告的情况 - 因为这属于正常情况。 My recommendation is to either have a standard set of your own ads, for example promoting features of your own app, or utilize another ad network to fill ads when iAd doesn't serve you one.我的建议是要么拥有一组标准的您自己的广告,例如宣传您自己的应用程序的功能,要么在 iAd 不为您提供广告时利用另一个广告网络来填充广告。

Here is a simple sample of how to hide or show ads depending on whether they were served or not:以下是如何根据是否投放广告来隐藏或显示广告的简单示例:

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    adView.hidden = NO;
    NSLog(@"Has ad, showing ad");
}


-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    adView.hidden = YES;
    NSLog(@"Has no ads, hidind ad");
}

Hope this helps.希望这可以帮助。

I know the question is about 6 years old but I had the same problem.我知道这个问题大约有 6 年的历史,但我遇到了同样的问题。 What worked for me (in Flutter):什么对我有用(在 Flutter 中):

import 'package:firebase_admob/firebase_admob.dart';

InterstitialAd _interstitialAd;
bool _isInterstitialAdReady;

void prepAd(){
  initState();
  _loadInterstitialAd();
}

void runAd() {
  _interstitialAd.show();
}

void initState() {
  _isInterstitialAdReady = false;
  _interstitialAd = InterstitialAd(
    adUnitId: InterstitialAd.testAdUnitId,
    listener: _onInterstitialAdEvent,
  );
}


void _loadInterstitialAd() {
  _interstitialAd.load();
}
// TODO: Implement _onInterstitialAdEvent()
void _onInterstitialAdEvent(MobileAdEvent event) {
  switch (event) {
    case MobileAdEvent.loaded:
      _isInterstitialAdReady = true;
      break;
    case MobileAdEvent.failedToLoad:
      _isInterstitialAdReady = false;
      print('Failed to load an interstitial ad');
      break;
    case MobileAdEvent.closed:
      dispose();
      prepAd();
      break;
    default:
    // do nothing
  }
}

void dispose() {// TODO: Dispose InterstitialAd object
  _interstitialAd?.dispose();
}

I ran prepAd() once in the beginning and then just runAd() when I need it.我在开始时运行了 prepAd() 一次,然后在需要时运行了 runAd()。 You can check _isInterstitialAdReady == true inside runAd() if you want如果需要,您可以在 runAd() 中检查 _isInterstitialAdReady == true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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