【问题标题】:AdMob Ios Error: Failed to receive ad with error: Request Error: No ad to showAdMob Ios 错误:无法接收广告并出现错误:请求错误:没有广告可展示
【发布时间】:2014-03-08 17:26:03
【问题描述】:

我会将 ADMOB 添加到我的 xcode 项目中,但是当在 iphone 和模拟器上对其进行测试时,我收到此错误:

AdMob Ios 错误:无法接收广告并出现错误:请求错误:没有广告可展示。

我的代码 Banner.h:

#import <UIKit/UIKit.h>
#import "GADBannerViewDelegate.h"

@class GADBannerView, GADRequest;

@interface BannerExampleViewController : UIViewController
    <GADBannerViewDelegate> {
  GADBannerView *adBanner_;
}

@property (nonatomic, retain) GADBannerView *adBanner;

- (GADRequest *)createRequest;

@end 

横幅.m

#import "BannerExampleViewController.h"
#import "GADBannerView.h"
#import "GADRequest.h"
#import "SampleConstants.h"

@implementation BannerExampleViewController

@synthesize adBanner = adBanner_;

#pragma mark init/dealloc

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

  // Initialize the banner at the bottom of the screen.
  CGPoint origin = CGPointMake(0.0,
                               self.view.frame.size.height -
                               CGSizeFromGADAdSize(kGADAdSizeBanner).height);

  // Use predefined GADAdSize constants to define the GADBannerView.
  self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                                  origin:origin]
                    autorelease];

  // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
  // before compiling.
  self.adBanner.adUnitID = kSampleAdUnitID;
  self.adBanner.delegate = self;
  [self.adBanner setRootViewController:self];
  [self.view addSubview:self.adBanner];
  self.adBanner.center =
      CGPointMake(self.view.center.x, self.adBanner.center.y);
  [self.adBanner loadRequest:[self createRequest]];
}

- (void)dealloc {
  adBanner_.delegate = nil;
  [adBanner_ release];
  [super dealloc];
}

- (NSUInteger)supportedInterfaceOrientations {
  return UIInterfaceOrientationMaskPortrait;
}

#pragma mark GADRequest generation

// Here we're creating a simple GADRequest and whitelisting the application
// for test ads. You should request test ads during development to avoid
// generating invalid impressions and clicks.
- (GADRequest *)createRequest {
  GADRequest *request = [GADRequest request];

  // Make the request for a test ad. Put in an identifier for the simulator as
  // well as any devices you want to receive test ads.
  request.testDevices =
      [NSArray arrayWithObjects:@"6a47e320f03fe2ab9854afe2e5708321", nil];
  return request;
}

#pragma mark GADBannerViewDelegate impl

// We've received an ad successfully.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
  NSLog(@"Received ad successfully");
}

- (void)adView:(GADBannerView *)view
    didFailToReceiveAdWithError:(GADRequestError *)error {
  NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
}

@end

【问题讨论】:

  • 一切看起来都不错,确保您的 AdMob 的“kSampleAdUnitID”键是完美的。
  • @D-eptdeveloper 是的.. 我确定
  • 同样的错误:无法接收广告并出现错误:请求错误:没有广告可展示。
  • 尝试替换这一行我对 request.testDevices = [NSArray arrayWithObjects: nil]; 有疑问删除密钥“6a47e320f03fe2ab9854afe2e5708321”
  • 有效!谢谢你的时间..救了我..它在生产模式下工作吗?

标签: ios ios-simulator admob


【解决方案1】:

还有一点需要指出 - 如果您的横幅空间宽度/高度设置为 ot 0,您将收到完全相同的错误。我目前正在尝试解决此问题,因为我只想在成功加载广告的情况下在屏幕上为广告视图设置动画。

【讨论】:

  • 知道了,Admob 不喜欢我们在横幅视图中使用隐藏。但它喜欢我们从 and 中删除和添加到超级视图。动画不太优雅。但没有错误!
  • 嗨你解决了这个..身高问题
  • 不要设置视图isHidden属性。不要将视图高度设置为 0。如果要在无法加载广告的情况下隐藏视图,请使用 adView(_: didFailToReveiveAdWithError) 方法并将视图高度设置为 1 而不是 0
【解决方案2】:

这是因为服务器还没有更新。 您应该等待 15 分钟再试一次,它会正常工作。

PS:记得将 kSampleAdUnitID 替换为您在 Admob 中的 App ID

当我使用我的 ID 进行测试时,此代码可以正常工作

【讨论】:

  • 你怎么知道我们应该等 15 分钟?
  • 服务器没有立即响应,这就是你应该等待的原因。如果您添加您的应用并让您的游戏立即运行,它将无法运行,因为它不在系统中。
  • 啊,你的意思是,添加后等待 15 分钟?广告之间的间隔如何?
  • 我的意思是在您将应用添加到服务器 Admob 后等待 15 分钟。在您的游戏中,您只需调用它,它会在 2 秒后出现 ^.^
  • Ohhhh.. 该应用程序已添加到服务器 Admob。我的问题是有时没有广告,有时有广告...
猜你喜欢
  • 2016-10-16
  • 1970-01-01
  • 2014-02-02
  • 1970-01-01
  • 2018-08-15
  • 1970-01-01
  • 2018-01-06
  • 2016-12-30
  • 2012-11-09
相关资源
最近更新 更多