ios Admob bannerView 请求错误:没有可显示的广告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39108558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:58:51  来源:igfitidea点击:

Admob bannerView Request Error: No ad to show

iosobjective-ccocos2d-iphoneadmob

提问by Gil Beyruth

I'm having this issue on one of my ads for an ios game

我在我的一个 ios 游戏广告中遇到了这个问题

Here is my code, the odd thing is that if I add the device on the request.testDevices list it displays the demo banner, if I remove from testDevices, it does not show a real banner, but if I change my bundleIdentifier on XCODE, it shows a real banner,so I believe its something with my admob account, does anyone ever got something like it?

这是我的代码,奇怪的是,如果我在 request.testDevices 列表中添加设备,它会显示演示横幅,如果我从 testDevices 中删除,它不会显示真正的横幅,但是如果我在 XCODE 上更改我的 bundleIdentifier,它显示了一个真正的横幅,所以我相信它与我的 admob 帐户有关,有人有过类似的东西吗?

Its always failing with this error:

它总是因此错误而失败:

AdView didFailToReceiveAdWithError --------------------------- : Error Domain=com.google.ads Code=1 "Request Error: No ad to show." UserInfo={NSLocalizedDescription=Request Error: No ad to show., NSLocalizedFailureReason=Request Error: No ad to show.}

AdView didFailToReceiveAdWithError --------------------------- : Error Domain=com.google.ads Code=1 “请求错误:没有要显示的广告。 ” UserInfo={NSLocalizedDescription=请求错误:没有要显示的广告。,NSLocalizedFailureReason=请求错误:没有要显示的广告。}

On my AppDelegate.m

在我的 AppDelegate.m 上

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Use Firebase library to configure APIs
    [FIRApp configure];
    [[FIRAnalyticsConfiguration sharedInstance] setAnalyticsCollectionEnabled:YES];
    // Initialize Google Mobile Ads SDK
    [GADMobileAds configureWithApplicationID:@"ca-app-pub-xx~xx"];
    /* other stuff here... */

}

on my rootViewController.m

在我的 rootViewController.m 上

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    bannerViewAdded = NO;
    interstitialViewAdded = NO;

   [self addBanner];
   // ..... more stuff here;
 }

- (void)addBanner{

    NSLog(@"CALL ADD BANNER ROOTVIEWCONTROLLER");

    if(!bannerViewAdded && ![MKStoreManager isFeaturePurchased:kFeatureAId]){

    NSLog(@"ADD BANNER ROOTVIEWCONTROLLER");
    CGSize size = [[CCDirector sharedDirector] winSize];


    // Create adMob ad View (note the use of various macros to detect device)
    if (IS_IPAD || IS_IPADHD) {
        bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeLeaderboard];
        bannerView.center = CGPointMake(size.width/2, (size.height-CGRectGetHeight(bannerView.frame)/2)-2);
    }
    else if (IS_IPHONE6) {
        bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
        bannerView.center = CGPointMake(size.width/2, (size.height-CGRectGetHeight(bannerView.frame)/2)-2);
    }
    else if (IS_IPHONE6P) {
        bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
        bannerView.center = CGPointMake(size.width/2, (size.height-CGRectGetHeight(bannerView.frame)/2)-2);
    }
    else {
        // boring old iPhones and iPod touches
        bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
        bannerView.center = CGPointMake(size.width/2, (size.height-CGRectGetHeight(bannerView.frame)/2)-2);
    }

    //[bannerView setBackgroundColor:[UIColor blueColor]];

    // Need to set this to no since we're creating this custom view.
    //bannerView.translatesAutoresizingMaskIntoConstraints = NO;

    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
    // before compiling.

    // Replace this ad unit ID with your own ad unit ID.
    bannerView.adUnitID = @"ca-app-pub-xx/xx";
    bannerView.rootViewController = self;
    bannerView.delegate = self;
    [self.view addSubview:bannerView];


    GADRequest *request = [GADRequest request];
    //request.testDevices = @[ kGADSimulatorID ];
    //request.testDevices = @[  @"xx", @"xx"  , kGADSimulatorID ];

    [bannerView loadRequest:request];
    bannerViewAdded = YES;
    }

}

- (void)removeBanner {
  //admob
  if(bannerViewAdded){
      bannerViewAdded = NO;
      [bannerView removeFromSuperview];
      [bannerView release];
      bannerView = nil;
  }
  //No AdMOB
  if(localBannerAdded){
      localBannerAdded = NO;
      [localBannerButton removeFromSuperview];
      [localBannerButton release];
      localBannerButton = nil;
  }
}


- (void)addInterstitial{

    if(!interstitialViewAdded && ![MKStoreManager isFeaturePurchased:kFeatureAId]){
        NSLog(@"INIT INTERSTITIAL ROOTVIEWCONTROLLER");
        interstitialView =  [[GADInterstitial  alloc] initWithAdUnitID:@"ca-app-pub-xx/xx"];

        GADRequest *request = [GADRequest request];
        // Requests test ads on devices you specify. Your test device ID is printed to the console when
        // an ad request is made. GADBannerView automatically returns test ads when running on a
        // simulator.
        //request.testDevices = @[ kGADSimulatorID, @"xxx", @"xxx" ];
        [interstitialView loadRequest:request];
        [interstitialView setDelegate:self];

    }

}

- (void)adView:(GADBannerView *)gadBannerView didFailToReceiveAdWithError:(GADRequestError *)error{
    NSLog(@"AdView didFailToReceiveAdWithError --------------------------- : %@",  error);
    [self removeBanner];
    if(!localBannerAdded){
        CGSize size = [[CCDirector sharedDirector] winSize];
        localBannerButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
        localBannerButton.frame = CGRectMake(0.0, 0.0, 320.0, 50.0);
        [localBannerButton setTitle:@"DOWNLOAD MORE FREE GAMES" forState:UIControlStateNormal];
        localBannerButton.backgroundColor = [UIColor whiteColor];//[UIColor clearColor];
        [localBannerButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
        [self.view addSubview:localBannerButton];

        [localBannerButton setCenter:CGPointMake(self.view.center.x,(size.height-CGRectGetHeight(localBannerButton.frame)/2)-2)];

        // Add Target-Action Pair
        [localBannerButton addTarget:self action:@selector(openAppStore:) forControlEvents:UIControlEventTouchUpInside];
        localBannerAdded = YES;
    }
 }

回答by Ibrahim

I just had this error today, the problem for me was simple, it was because the adUnitIDis basically still new. I had to wait more than 2 hours after creating the adUnitIDin order for the ads to be served.

我今天刚遇到这个错误,对我来说问题很简单,因为adUnitID它基本上还是新的。创建后我不得不等待 2 个多小时adUnitID才能投放广告。

If you have this error, and some of your adUnitIDsserve ads and some don't. You're highly likely having the same issue, and the only way to fix it is to wait.

如果您遇到此错误,并且您的一些adUnitIDs服务广告和一些没有。您很可能遇到了同样的问题,解决它的唯一方法就是等待。

回答by Sangram Shivankar

The ad server will return this message mainly because there are no ads for your ad unit id. Check whether your ad unit id is proper or not. You will get the same error if either your banner width/height is 0. Make sure that your adUnitID is perfect. or check following links its may help you https://groups.google.com/forum/#!topic/google-admob-ads-sdk/ioXU2nX9W28

广告服务器将返回此消息主要是因为您的广告单元 ID 没有广告。检查您的广告单元 ID 是否正确。如果您的横幅宽度/高度为 0,您将收到同样的错误。确保您的 adUnitID 是完美的。或查看以下链接,它可能对您有所帮助 https://groups.google.com/forum/#!topic/google-admob-ads-sdk/ioXU2nX9W28

AdMob Legacy Publisher ID not showing ads

AdMob 旧版发布商 ID 未展示广告

回答by Tony

I had just created a new account and seen that problem. When checking my account there was a message shown on the top of admob page: "Your ad units are not displaying ads because you haven't provided your account payments information yet.". Click on the button Fix it, fill the form and the ads will be shown within few hours

我刚刚创建了一个新帐户并看到了这个问题。检查我的帐户时,admob 页面顶部显示一条消息:“您的广告单元未展示广告,因为您尚未提供帐户付款信息。”。点击按钮修复它,填写表格,广告将在几个小时内显示

回答by monkjj

I met this error too. Both my banner and interstitial ads failed with this error. I found that it is my mistake to change UserAgent globally, after I change UserAgent to default it works well.

我也遇到了这个错误。我的横幅广告和插页式广告均因此错误而失败。我发现全局更改 UserAgent 是我的错误,在我将 UserAgent 更改为默认值后它运行良好。

回答by Ric Santos

Make sure you are using the test ad IDs when in a debug session.

确保您在调试会话中使用测试广告 ID。

https://developers.google.com/admob/ios/banner?hl=en-US

https://developers.google.com/admob/ios/banner?hl=zh-CN

The easiest way to load test ads is to use our dedicated test ad unit ID for iOS banners: ca-app-pub-3940256099942544/2934735716

加载测试广告的最简单方法是使用我们针对 iOS 横幅的专用测试广告单元 ID:ca-app-pub-3940256099942544/2934735716

回答by Muhammad Nayab

This error could happen if you have not setup your payment and billing information in your AdMob account. As per Admob after you setup the payment details, it can take up to 2 hours before it would be completely functional

如果您尚未在 AdMob 帐户中设置付款和结算信息,则可能会发生此错误。根据 Admob 设置付款详细信息后,最多可能需要 2 小时才能完全正常运行

Billing and Payments

账单和付款

回答by Husam

This solved my problem

这解决了我的问题

  1. changing banner id to example id.
  2. run the app then .
  3. changing id back to production id.
  1. 将横幅 ID 更改为示例 ID。
  2. 然后运行应用程序。
  3. 将 id 改回生产 id。

回答by Dejan Atanasov

For me, the reason why it started showing this is that I didn't have any payment methods set up on my AdMob account.

对我来说,它开始显示这一点的原因是我的 AdMob 帐户中没有设置任何付款方式。

Once I have set this up, the error has disappeared and ads started showing instantly.

设置完成后,错误消失了,广告立即开始显示。

Hope this helps someone!

希望这可以帮助某人!

回答by yuanjilee

One possible reason is a Constraintbug.

一个可能的原因是约束错误。

you should guarantee your bannerView's constraint to other views is right

你应该保证你的bannerView对其他视图的约束是正确的

回答by Rawand Saeed

I had the same issue when testing the sample application on my phone. I fixed with the following steps:

在我的手机上测试示例应用程序时,我遇到了同样的问题。我通过以下步骤修复:

Reset Advertising identifier on iPhone 6, Go to:

在 iPhone 6 上重置广告标识符,转到:

Settings -> Privacy -> Advertising -> Reset Ad identifier

设置 -> 隐私 -> 广告 -> 重置广告标识符