Custom Ad Size
In addition to standard AdMob ad units, DFP allows you to serve an ad unit of any size in the app. Please note that the ad size (width and height) defined for the ad request must match the size of the ad displayed in the application (i.e. DFPBannerView).
Example:
// 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];
Note. DFP does not currently support smart banners.
Multiple Ad Sizes
DFP allows you to specify several ad sizes that may be eligible for service in DFPBannerView. To use this function, you must complete three steps:
In the DFP user interface, create a campaign that targets the same ad unit thatβs associated with ads of different sizes. In your application, set the validAdSizes property to 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;
Implement the GADAdizeDelegate method to determine the size of the ad.
@protocol GADAdSizeDelegate <NSObject> - (void)adView:(GADBannerView *)view willChangeAdSizeTo:(GADAdSize)size; @end
Remember to set the delegate using setAdSizeDelegate: before making a request for the declaration.
[bannerView_ setAdSizeDelegate:self]
Be sure to set the GADBannerView adSizeDelegate property to nil before releasing the view:
- (void)dealloc { bannerView_.adSizeDelegate = nil;