如何在IOS项目显示GADInterstitial

如何在IOS项目显示GADInterstitial

本文介绍了如何在IOS项目显示GADInterstitial?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//  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

推荐答案

更​​改广告的尺寸,以全屏幕中的AdMob网站的设置。

Change the ad size to full screen in the settings in admob website.

这篇关于如何在IOS项目显示GADInterstitial?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 12:11