4
我的應用在UIScrollView中提供了三個廣告(通過DoubleClick for Publisher)。我使用舊版AdMob SDK for iOS,並且一切正常。我決定下載新版本,因爲AppStore存在一些問題。一旦我添加新版本,我收到錯誤:DFP廣告管理系統問題:沒有要顯示的廣告
Error Domain=com.google.ads Code=1 "Request Error: No ad to show." UserInfo=0x14e88e60 {NSLocalizedDescription=Request Error: No ad to show., NSLocalizedFailureReason=Request Error: No ad to show.}
廣告具有自定義尺寸的廣告素材(320x125)。 UIScrollView添加的是960x125,它被放置爲UITableView的頭部。
橫幅代碼:
- (void)viewDidLoad {
[super viewDidLoad];
DFPBannerView *bannerView = (DFPBannerView *)self.view;
[self preventBannerCaptureTouch:bannerView];
// Create a view of the standard size at the bottom of the screen.
// Available AdSize constants are explained in GADAdSize.h.
//bannerView = [[DFPBannerView alloc] initWithAdSize:CG];
bannerView.adSize = GADAdSizeFromCGSize(CGSizeMake(320, 125));
// Specify the ad's "unit identifier." This is your DFP ad unit ID.
bannerView.adUnitID = self.adUnitID;
[bannerView setAppEventDelegate:self];
[bannerView setDelegate:self];
bannerView.rootViewController = self.bannerOwner;
// Initiate a generic request to load it with an ad.
GADRequest *request = [[GADRequest alloc] init];
//request.testDevices = [NSArray arrayWithObjects: nil];
[bannerView loadRequest:request];
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinner.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
[self.view addSubview:spinner];
[spinner startAnimating];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)preventBannerCaptureTouch:(GADBannerView*)bannerView {
for (UIWebView *webView in bannerView.subviews) {
if ([webView isKindOfClass:[UIWebView class]]) {
webView.scrollView.bounces = NO;
for (UIGestureRecognizer *gestureRecognizer in webView.gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:NSClassFromString(@"GADImpressionTicketGestureRecognizer")]) {
gestureRecognizer.delegate = self;
}
}
for (id view in [[[webView subviews] objectAtIndex:0] subviews]) {
if ([view isKindOfClass:NSClassFromString(@"UIWebBrowserView")]) {
for (UIGestureRecognizer *recognizer in [view gestureRecognizers]) {
if ([recognizer isKindOfClass:NSClassFromString(@"UIWebTouchEventsGestureRecognizer")]) {
[view removeGestureRecognizer:recognizer];
}
}
return;
}
}
}
[webView setTintColor:[UIColor whiteColor]];
}
}
- (void)viewWillUnload {
[super viewWillUnload];
DFPBannerView *bannerView = (DFPBannerView *)self.view;
bannerView.appEventDelegate = nil;
bannerView.delegate = nil;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.bannerSlider bannerTouchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self.bannerSlider bannerTouchesEnded:touches withEvent:event];
}
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
[spinner stopAnimating];
}
- (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(@"GOOGLE Ad ERROR: %@", error);
[spinner stopAnimating];
}
的UIScrollView的代碼:
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *view = (UIScrollView *)self.view;
view.bounces = NO;
// @"/6499/example/banner"
GWBannerController *oneController = [[GWBannerController alloc] initWithNibName:@"BannerView" bundle:nil bannerOwner:self.bannerOwner bannerSlider:self ID:@"/XXX/iOSLeaderBanner_One"];
//GWBannerController *oneController = [[GWBannerController alloc] initWithNibName:@"BannerView" bundle:nil bannerOwner:self.bannerOwner bannerSlider:self ID:@"/6499/example/banner"];
oneController.view.frame = CGRectMake(0, 0, 320, 125);
[view addSubview:oneController.view];
[bannerArray addObject:oneController];
GWBannerController *twoController = [[GWBannerController alloc] initWithNibName:@"BannerView" bundle:nil bannerOwner:self.bannerOwner bannerSlider:self ID:@"/XXX/iOSLeaderBanner_Two"];
twoController.view.frame = CGRectMake(320, 0, 320, 125);
[view addSubview:twoController.view];
[bannerArray addObject:twoController];
GWBannerController *threeController = [[GWBannerController alloc] initWithNibName:@"BannerView" bundle:nil bannerOwner:self.bannerOwner bannerSlider:self ID:@"/XXX/iOSLeaderBanner_Three"];
threeController.view.frame = CGRectMake(640, 0, 320, 125);
[view addSubview:threeController.view];
[bannerArray addObject:threeController];
[view setContentSize:CGSizeMake(960, 125)];
[self startTimer];
}