Cairoeditor
Cairoeditor

Reputation: 35

admob interstitial not displaying on ios?

its been weeks that i have been trying to display admob interstitial ads with no luck, i have managed to display normal banner ads but i dont know the right way to display interstitial, here is the code i tried (following admob guide)

in my mainViewcontroller.h

@interface MainViewController : CDVViewController 

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

}

and on my 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]];



}

Upvotes: 1

Views: 4937

Answers (1)

Suhas
Suhas

Reputation: 1500

You need to wait until the ad loads successfully and only then present it in case of Interstitial ads. Otherwise the ads wont show up.

To do this confirm to the GADInterstitialDelegate protocol and set your view controller as the delegate of interstitial_.

interstitial_.delegate = self;

Then implement interstitialDidReceiveAd as follows.

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

Upvotes: 7

Related Questions