显示AdMob的广告与iPhone自定义大小 [英] Display admob ads with a custom size in iPhone

查看:1209
本文介绍了显示AdMob的广告与iPhone自定义大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以显示AdMob的广告与iPhone自定义尺寸,如280x50,不为320x50一般?

Can I display admob ads with a custom size in iphone, such as 280x50, not 320x50 typically ?

推荐答案

在除了标准的AdMob的广告单元,DFP广告管理系统可以让你满足任何规模的广告单元到应用程序中。注意,广告的大小(宽度,高度),用于广告请求确定应该匹配在应用程序(即DFPBannerView)中显示的广告视图的尺寸

Custom Ad Size

In addition to the standard AdMob ad units, DFP allows you to serve any sized ad unit into an application. Note that the ad size (width, height) defined for an ad request should match the dimensions of the ad view displayed on the application (i.e. 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目前不支持智能横幅

Note: DFP does not currently support Smart Banners.

DFP允许你指定哪个有资格担任成DFPBannerView多个广告尺寸。有必要的,以三个步骤来使用此功能:

DFP allows you to specify multiple ad sizes which may be eligible to serve into a DFPBannerView. There are three steps needed in order to use this feature:

在DFP广告管理系统的用户界面,创建针对一个与不同大小的广告相关联的同一个广告单元的行项目。 在您的应用程序,在DFPBannerView设置validAdSizes属性:

In the DFP UI, create a line item targeting the same ad unit that is associated with different size creatives. In your application, set the validAdSizes property on DFPBannerView:

// 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方法来检测广告尺寸的变化。

Implement the GADAdSizeDelegate method to detect an ad size change.

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

记住使用setAdSizeDelegate设置委托:制作广告请求之前

Remember to set the delegate using the setAdSizeDelegate: before making the request for an ad.

[bannerView_ setAdSizeDelegate:self];

请务必释放视图之前到GADBannerView的adSizeDelegate属性为nil设置:

Be sure to set the GADBannerView's adSizeDelegate property to nil before releasing the view:

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

 // Don't release the bannerView_ if you are using ARC in your project
 [bannerView_ release];
 [super dealloc];
}

这篇关于显示AdMob的广告与iPhone自定义大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆