0

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 Delegates で [ad presentFromRootViewController:self]; を呼び出しています。

しかし、それでもカスタム広告を取得できません。助けてください。

4

2 に答える 2

0

GADInterstitialは、アプリに広告を表示する興味深い方法ですが、ちょっと難しい方法でもあります。このに従って、次の手順を実行します。

  • まず、それらが表示されるように環境を設定する必要があります。GoogleAdMobAdsSdkiOS、できれば最新のものをダウンロードします。SDK をプロジェクトに追加しますが、SDK の AddOns フォルダーにあるサンプル プロジェクトを忘れずに削除してください。

  • 次に、次のフレームワークをプロジェクト>>ビルド フェーズ>>バイナリとライブラリのリンクに追加します。

    • AdSupport.framework (< iOS7 向けのケータリングの場合はオプションを選択)
    • StoreKit.framework
    • CoreData.framework
    • CoreAudio.framework
    • AVFoundation.framework
    • MessageUI.framework
    • AudioTool.framework
    • libGoogleAdMobAds.a (SDK フォルダーに配置)
  • 基本は完了です。次に、Ads を表示する 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.m に移動する必要があります。

   - (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_」は、Ad が正常にロードされたかどうかを常にチェックし、正常にロードされたときに、ユーザーがまだ ViewController にいる場合は、ViewController で Ad を撮影します。静的 kSampleAdUnitID は、常に機能する sampleId です。それでおしまい。コードを実行し、選択した ViewController でインタースティシャル広告を見つけます。私が助けてくれることを願っています。乾杯!:)

于 2014-05-06T23:52:12.563 に答える
0

プロパティには独自の一意のものを使用する必要がありidますadUnitID

于 2012-08-16T09:54:33.630 に答える