1

如何在 ios 项目中显示 GADInterstitial?我收到错误“请求错误:没有广告可显示”,但 admob 正在我的另一个项目中工作。

//  ViewController.h
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
#import "GADCustomEventBanner.h"
#import "GADInterstitial.h"

@interface ViewController : UIViewController <GADInterstitialDelegate>
{
    UIButton *interstitialButton_;
    GADInterstitial *interstitial_;
}

@property(nonatomic, retain) IBOutlet UIButton *interstitialButton;
@property(nonatomic, retain) GADInterstitial *interstitial_;

- (IBAction)showInterstitial:(id)sender;

@end



//ViewController.h
#import "ViewController.h"

@implementation ViewController
@synthesize interstitialButton ;
@synthesize interstitial_;

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

- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
    // Alert the error.
    UIAlertView *alert = [[[UIAlertView alloc]
                           initWithTitle:@"GADRequestError"
                           message:[error localizedDescription]
                           delegate:nil cancelButtonTitle:@"Drat"
                           otherButtonTitles:nil] autorelease];
    [alert show];

    interstitialButton_.enabled = YES;
}

-(void)interstitialWillPresentScreen:(GADInterstitial *)ad{
    NSLog(@"on screen");
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
    [interstitial presentFromRootViewController:self];
    interstitialButton_.enabled = YES;
    [self showInterstitial:nil];
}

- (IBAction)showInterstitial:(id)sender {

    self.interstitial_ = [[[GADInterstitial alloc] init] autorelease];

    self.interstitial_.delegate = self;

    self.interstitial_.adUnitID = MY_ADMOB_KEY;   // this key is working in admob //   
    GADRequest *request = [GADRequest request];
    request.testing = YES;
    [self.interstitial_ loadRequest: request];
    interstitialButton_.enabled = NO;
}

@end

在此处输入图像描述

4

2 回答 2

1

在 admob 网站的设置中将广告尺寸更改为全屏。

于 2012-09-18T04:49:34.150 回答
0

self.interstitial_.adUnitID = MY_ADMOB_KEY; // 这个键在 admob 中工作

检查此评论,并将其替换为:

self.interstitial_.adUnitID = @"ca-app-pub-xxxxxxxxxxx"; // 这个键在 admob 中工作

你应该得到你自己的 adUnitID 表单 admob

于 2014-06-09T08:17:58.717 回答