admos interstitial没有在ios上显示?

时间:2013-09-26 03:28:52

标签: ios objective-c xcode admob

这几周我一直试图显示adob插页式广告没有运气,我设法显示正常的横幅广告,但我不知道显示插页式广告的正确方法,这里是我试过的代码(按照admob指南)

在我的mainViewcontroller.h

@interface MainViewController : CDVViewController 

<GADBannerViewDelegate> {
    GADBannerView *adBanner_;
    GADInterstitial *interstitial_;

}

和我的mainViewController.m

@implementation MainViewController


@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];


    interstitial_ = [[GADInterstitial alloc] init];
    interstitial_.adUnitID = @"XXXXXXXXXXXXXX";
    [interstitial_ loadRequest:[GADRequest request]];
    [interstitial_ presentFromRootViewController:self];



    // Initialize the banner at the bottom of the screen.
    [adBanner_ setFrame:CGRectMake(100,
                                     100,
                                     adBanner_.bounds.size.width,
                                     adBanner_.bounds.size.height)];

    // Use predefined GADAdSize constants to define the GADBannerView.
    self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                                    ]
                     autorelease];

    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
    // before compiling.
    self.adBanner.adUnitID = @"XXXXXXXXXXXXXXX";
    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]];



}

1 个答案:

答案 0 :(得分:7)

您需要等到广告成功加载,然后才会出现插页式广告。否则广告就不会出现了。

为此,请确认GADInterstitialDelegate协议并将视图控制器设置为插页式广告_的代表。

interstitial_.delegate = self;

然后按如下方式实现interstitialDidReceiveAd。

- (void)interstitialDidReceiveAd:(DFPInterstitial *)ad
{
    [interstitial_ presentFromRootViewController:self];
}