iphone - 如何在 ios 项目中显示 GADInterstitial?

标签 iphone objective-c ios admob

如何在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

enter image description here

最佳答案

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

关于iphone - 如何在 ios 项目中显示 GADInterstitial?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12171323/

相关文章:

iphone - AVAudioPlayer:MP3 文件无法在设备上播放,但可以在模拟器 (iOS 6) 中播放

objective-c - CoreBluetooth——在设备锁定时发现 BLE 外围设备

iphone - 当我们从表中重新加载数据时,UITable View 数据源和委托(delegate)的顺序是什么?

ios - 从 Settings.bundle 获取切换

ios - 为什么按下 UISearchbar 上的取消按钮时会出现 UIKeyboard?

iphone - 如何在隐藏控件时仅捕获 MPMoviePlayerController View 上的单击/点击?

iphone - iOS6 上的 IOHIDEventSystemCreate 失败

iphone - AFNetworking是否有连接失败后的重连方法

ios - 计算/伪造 UILabel 中的行高变化