简体   繁体   中英

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



}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM