3

Xcode プロジェクトに ADMOB を追加しますが、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
4

2 に答える 2

6

指摘すべきもう 1 つの点 - バナー スペースの幅/高さが 0 以外に設定されている場合、まったく同じエラーが発生します。広告が正常に読み込まれた場合にのみ、画面上で広告ビューをアニメーション化する必要があるため、現在、この問題を回避しようとしています。

于 2014-03-08T09:26:03.143 に答える