2012-07-13 86 views
0

的GADInterstitial定製廣告我已經得到的GADInterstitial定製廣告一個問題,我已經嘗試了本代碼沒有工作

if(nil != m_pBannerView) 
{ 
    m_pBannerView.delegate = nil; 
    [m_pBannerView release]; 
    m_pBannerView = nil; 
} 
m_pBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; 
m_pBannerView.delegate = self; 
m_pBannerView.rootViewController = self; 
m_pBannerView.adUnitID = @"AdMob Publisher ID"; 
m_pBannerView.rootViewController = self; 
[self.view addSubview:m_pBannerView]; 

GADRequest *request = [GADRequest request]; 
request.testing = YES; 
[m_pBannerView loadRequest:request]; 

if(nil != m_pInterstitial) 
{ 
    [m_pInterstitial release]; 
    m_pInterstitial = nil; 
} 

m_pInterstitial = [[GADInterstitial alloc] init]; 
m_pInterstitial.delegate = self; 
m_pInterstitial.adUnitID = @"INTERSTITIAL_AD_UNIT_ID"; 

GADRequest *interstialRequest = [GADRequest request]; 
interstialRequest.testing = YES; 
[m_pInterstitial loadRequest: interstialRequest]; 

} 而在代表們的GADInterstitial我打電話[廣告presentFromRootViewController:自我]。

但我仍然無法獲得定製廣告,請幫助我。

+0

我有同樣的問題,使用loadAndDisplayRequest:usingWindow:initialImage:描述[這裏](https://developers.google.com/mobile-ads-sdk/docs/ios/advanced) – thomers 2012-07-20 12:48:15

回答

0

你必須用你自己獨特的idadUnitID財產

+0

改善您的文章的質量,請包括如何/爲什麼此代碼將解決問題。 – 2012-10-04 09:55:27

0

的GADInterstitial是在你的應用中展示廣告的一種有趣的方式,和那種一個棘手太。在此之後example,讓追求以下步驟:

  • 首先,我們需要建立的環境,使它們顯示在所有。 下載GoogleAdMobAdsSdkiOS,最好是最新的。將SDK的 添加到您的項目中,但請記得刪除SDK中AddOns文件夾中的示例 項目。

  • 接下來,在你的項目中添加以下框架>>構建 階段>>鏈接二進制與圖書館:

    • AdSupport.framework程式(選擇可選如果迎合< iOS7)
    • StoreKit.framework
    • CoreData.framework
    • CoreAudio.framework
    • AVFoundation.framework
    • MessageUI.framework
    • AudioTool.framework
    • 的libGoogleAdMobAds.a(放置在SDK文件夾)
  • 的基礎是完整的。現在,我們需要選擇我們希望看到我們的廣告了的ViewController因此,這裏的一些代碼,這裏我們導入了頭的GADInterstitialDelegate,並與我們的MainViewController.h擴展它:

#import "GADInterstitialDelegate.h" 
    #define kSampleAdUnitID @"/6253334/dfp_example_ad/interstitial" 

    @class GADInterstitial; 
    @class GADRequest; 

    @interface MainViewController : UIViewController<GADInterstitialDelegate> 
    { 
     BOOL isLoaded_; 
     NSTimer *quickie_; 
    } 

    @property(nonatomic, strong) GADInterstitial *interstitial; 

//Make sure the delegate is handled properly. 
  • 現在我們需要移動到實現中,即在MainViewController中。L:

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view. 

     // FOLLOW THE CODE BELOW FOR ADMOD INTERESTIAL IMPLEMENTATION 
     [self initializeAds]; 
     quickie_ = [[NSTimer alloc] init]; 
     quickie_ = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showAdd) userInfo:nil repeats:YES]; 
    } 


    -(void)showAdd 
    { 
     if(isLoaded_ && [quickie_ isValid]) 
     { 
      [quickie_ invalidate]; 
      quickie_ = nil; 
      [self.interstitial presentFromRootViewController:self]; 
     } 
    } 

    - (GADRequest *)request 
    { 
     GADRequest *request = [GADRequest request]; 
     return request; 
    } 

    -(void)initializeAds 
    { 
     // Create a new GADInterstitial each time. A GADInterstitial will only show one request in its 
     // lifetime. The property will release the old one and set the new one. 
     self.interstitial = [[GADInterstitial alloc] init]; 
     self.interstitial.delegate = self; 

     // Note: kSampleAdUnitId is a staticApId for example purposes. For personal Ads update kSampleAdUnitId with your interstitial ad unit id. 
     self.interstitial.adUnitID = kSampleAdUnitID; 
     [self.interstitial loadRequest:[self request]]; 
    } 

    - (void)viewWillLayoutSubviews 
    { 
     [super viewWillLayoutSubviews]; 
     self.loadingSpinner.center = CGPointMake(CGRectGetWidth(self.view.bounds)/2, self.loadingSpinner.center.y); 
    } 

    - (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial 
    { 
     isLoaded_ = YES; 
    } 

    - (void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error 
    { 
     isLoaded_ = NO; 
    } 

    //----ADS IMPLEMENTATION TILL HERE--->// 

計時器 「quickie_」 這裏經常檢查,如果廣告已成功加載並當它,它拍攝的廣告ViewController如果用戶仍然在上面。靜態kSampleAdUnitID是一個始終有效的sampleId。而已。運行您的代碼並在您選擇的ViewController上找到您的插頁式廣告。 希望我幫忙。乾杯! :)