2013-09-26 112 views
1

我一直試圖展示admob插頁式廣告沒有運氣的周,我已經設法顯示正常的橫幅廣告,但我不知道正確的方式來顯示插頁式廣告,這裏是我試過的代碼(遵循admob指南)admob插頁式廣告在ios上不顯示?

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



} 

回答

6

您需要等到廣告加載成功,然後纔在插頁式廣告的情況下出示。否則,廣告不會出現。

爲此,請確認GADInterstitialDelegate協議並將視圖控制器設置爲interstitial_的委託。

interstitial_.delegate = self; 

然後執行interstitialDidReceiveAd,如下所示。

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

您必須將DFPInterstitial更改爲GADInterstitial !!!!然後它工作正常! - (void)interstitialDidReceiveAd:(GADInterstitial *)ad { [interstitial_ presentFromRootViewController:self]; } – basti12354

相關問題