ios - Admob bannerView 请求错误 : No ad to show

标签 ios objective-c cocos2d-iphone admob

我的一个 iOS 游戏广告出现了这个问题

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

它总是因为这个错误而失败:

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

在我的 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... */

}

在我的 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;
    }
 }

最佳答案

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

如果您遇到此错误,并且您的某些 adUnitID 转换广告而有些则不转换。您很可能遇到同样的问题,解决它的唯一方法就是等待。

关于ios - Admob bannerView 请求错误 : No ad to show,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39108558/

相关文章:

iphone - 从代码打开 map 应用程序 - 在哪里/如何找到 "Current Location"?

ios - SpriteKit UILabelNode 附加事件

ios - 无法将 AFNetworking 依赖项导入 Cocoapod

ios - Cocos2d + box2D 从世界中移除 Sprite

ios - Admob 导致 Cocos2d 触摸延迟

ios - 找不到 Cocos2D kazmath/kazmath.h 文件

ios - 使用 AVAudioSession 设置麦克风增益时出现不稳定行为

ios - 什么时候应该使用数据源(协议(protocol))与在属性或初始化上设置类数据?

iphone - MBProgress HUD 在 tableView 上的 reloadData 上崩溃应用程序

ios - 如何为 UITableView 部分页脚设置动画