4

通常320x50ではなく280x50などのカスタムサイズのAdMob広告をiPhoneに表示できますか?

4

8 に答える 8

6

カスタム広告サイズ

標準の AdMob 広告ユニットに加えて、DFP では任意のサイズの広告ユニットをアプリケーションに配信できます。広告リクエストに定義された広告サイズ (幅、高さ) は、アプリケーションに表示される広告ビュー (DFPBannerView) のサイズと一致する必要があることに注意してください。

例:

// Define custom GADAdSize of 280x30 for DFPBannerView
GADAdSize customAdSize = GADAdSizeFromCGSize(280, 30);
// Don't use autorelease if you are using ARC in your project
self.adBanner = [[[DFPBannerView alloc] initWithAdSize:customAdSize] autorelease];

注: DFP は現在、スマート バナーをサポートしていません。

複数の広告サイズ

DFP では、DFPBannerView に配信できる複数の広告サイズを指定できます。この機能を使用するには、次の 3 つの手順が必要です。

DFP UI で、異なるサイズのクリエイティブに関連付けられた同じ広告ユニットをターゲットとする広告申込情報を作成します。アプリケーションで、DFPBannerView に validAdSizes プロパティを設定します。

// Define an optional array of GADAdSize to specify all valid sizes that are appropriate
// for this slot. Never create your own GADAdSize directly. Use one of the
// predefined standard ad sizes (such as kGADAdSizeBanner), or create one using
// the GADAdSizeFromCGSize method.
//
// Note: Ensure that the allocated DFPBannerView is defined with an ad size. Also note
// that all desired sizes should be included in the validAdSizes array.  

GADAdSize size1 = GADAdSizeFromCGSize(CGSizeMake(120, 20));
GADAdSize size2 = GADAdSizeFromCGSize(CGSizeMake(250, 250));
GADAdSize size3 = GADAdSizeFromCGSize(CGSizeMake(320, 50));
NSMutableArray *validSizes = [NSMutableArray array];
[validSizes addObject:[NSValue valueWithBytes:&size1 objCType:@encode(GADAdSize)]];
[validSizes addObject:[NSValue valueWithBytes:&size2 objCType:@encode(GADAdSize)]];
[validSizes addObject:[NSValue valueWithBytes:&size3 objCType:@encode(GADAdSize)]];
bannerView_.validAdSizes = validSizes;

GADAdSizeDelegate メソッドを実装して、広告サイズの変更を検出します。

@protocol GADAdSizeDelegate <NSObject>
- (void)adView:(GADBannerView *)view willChangeAdSizeTo:(GADAdSize)size;
@end

広告をリクエストする前に、必ず setAdSizeDelegate: を使用してデリゲートを設定してください。

[bannerView_ setAdSizeDelegate:self];

ビューを解放する前に、必ず GADBannerView の adSizeDelegate プロパティを nil に設定してください。

- (void)dealloc {
 bannerView_.adSizeDelegate = nil;

 // Don't release the bannerView_ if you are using ARC in your project
 [bannerView_ release];
 [super dealloc];
}
于 2012-10-09T06:22:10.593 に答える
4

私は同じ問題を抱えていました。以前は、広告の UIView オブジェクトのフレームを変更することは可能でしたが、現在では即時にdidFailToReceiveAdWithError:.

DFPBannerView setSize:また、規格外のサイズで呼び出しても効果はありません。

私の解決策は、単純にのスケーリングを設定することでしたDFPBannerView:

    GADBannerView *retVal = [self.dfpAd];
    float scaleX = w / (retVal.adSize.size.width - 0.5f);
    float scaleY = h / (retVal.adSize.size.height - 0.5f);
    float scaleFactor = MAX(scaleX, scaleY);

    retVal.transform = CGAffineTransformMakeScale( scaleFactor, scaleFactor);

    //        [((DFPBannerView *) retVal) resize:GADAdSizeFromCGSize(CGSizeMake(w, h))]; // Of course not working....

    // iPhone 6 and above fix. Won't rescale correctly if you don't layout. Do this after addSubView!
    //        [retVal setNeedsLayout];
    //        [retVal layoutIfNeeded];

また、iPhone 6以降の修正にご注意ください。

于 2015-08-25T12:13:36.363 に答える
1

私の指示を試してください

YourviewController ヘッダー ファイル内

#import "GADBannerView.h"

@interface YourviewController : UIViewController 
{
  GADBannerView *admob_view;
}

YourViewcontroller 実装ファイルの後:

#import "MainViewController.h"
#import <QuartzCore/QuartzCore.h>
#define AdMob_ID @"a150349d7c43186" 

@implementation YourviewController 
{
  -(void)viewDidLoad
 {
    admob_view = [[GADBannerView alloc]
                  initWithFrame:CGRectMake(0.0,415.0,320,60)];//in this line mention your adview size

    admob_view.adUnitID = AdMob_ID;
    admob_view.rootViewController = self;
    [self.view addSubview:admob_view];


    GADRequest *r = [[GADRequest alloc] init];
    r.testing = YES;
    [admob_view loadRequest:r];

 }

}

上記のコードは次の行に注意してください。admob_view = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,415.0,320,60)];

CGRectMake(x,y,width,height)を使用して、次のコードの要件のように、admob 広告ビューを変更して割り当てることができます。

admob_view = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,415.0,280,50)];
于 2012-10-09T06:22:48.737 に答える