gpt4 book ai didi

ios - AdMob Ios 错误 : Failed to receive ad with error: Request Error: No ad to show

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:09:19 26 4
gpt4 key购买 nike

我会把 ADMOB 添加到我的 xcode 项目中,但是当在 iphone 和模拟器上测试它时我收到这个错误:

AdMob Ios Error: Failed to receive ad with error: Request Error: No ad to show.

我的代码 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

最佳答案

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

关于ios - AdMob Ios 错误 : Failed to receive ad with error: Request Error: No ad to show,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19295552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com