L'SDK Google Mobile Ads supporta le dimensioni fisse degli annunci per le situazioni in cui adattivi gli annunci banner non soddisfano le tue esigenze.
Nella tabella seguente sono elencate le dimensioni standard dei banner.
Dimensioni in dp (LxA) | Descrizione | Disponibilità | Costante AdSize |
---|---|---|---|
320 x 50 | Banner | Telefoni e tablet | GADAdSizeBanner |
320 x 100 | Banner grande | Telefoni e tablet | GADAdSizeLargeBanner |
300 x 250 | Rettangolo medio IAB | Telefoni e tablet | GADAdSizeMediumRectangle |
468 x 60 | Banner a dimensione intera IAB | Tablet | GADAdSizeFullBanner |
728 x 90 | Classifica IAB | Tablet | GADAdSizeLeaderboard |
Per definire le dimensioni del banner personalizzate, imposta le dimensioni utilizzando GADAdSizeFromCGSize
:
Swift
let adSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))
Objective-C
GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(250, 250));
Esempio di annunci banner di dimensioni fisse
Dimensioni annuncio personalizzate
Oltre alle unità pubblicitarie standard, Google Ad Manager ti consente di pubblicare
in un'app. Le dimensioni dell'annuncio (larghezza, altezza) definite per una richiesta di annuncio
deve corrispondere alle dimensioni della visualizzazione dell'annuncio (GAMBannerView
) mostrata nella
dell'app. Per impostare una dimensione personalizzata, utilizza GADAdSizeFromCGSize
.
Swift
// Define custom GADAdSize of 250x250 for GAMBannerView.
let customAdSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))
bannerView = GAMBannerView(adSize: customAdSize)
Objective-C
// Define custom GADAdSize of 250x250 for GAMBannerView
GADAdSize customAdSize = GADAdSizeFromCGSize(CGSizeMake(250, 250));
self.bannerView = [[GAMBannerView alloc] initWithAdSize:customAdSize];
Più dimensioni degli annunci
Ad Manager ti consente di specificare più dimensioni degli annunci che potrebbero essere idonee alla pubblicazione
in un GAMBannerView
. Per utilizzare questa funzionalità sono necessari tre passaggi
funzionalità:
Nell'interfaccia utente di Ad Manager, crea un elemento pubblicitario che ha come target la stessa unità pubblicitaria associate a creatività di dimensioni diverse.
Nell'app, imposta la proprietà
validAdSizes
suGAMBannerView
:Swift
// 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 GADAdSizeBanner), or create one using // the GADAdSizeFromCGSize method. // // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note // that all desired sizes should be included in the validAdSizes array. bannerView.validAdSizes = [NSValueFromGADAdSize(GADAdSizeBanner), NSValueFromGADAdSize(GADAdSizeMediumRectangle), NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSize(width: 120, height: 20)))]
Objective-C
// 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 GADAdSizeBanner), or create one using // the GADAdSizeFromCGSize method. // // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note // that all desired sizes should be included in the validAdSizes array. self.bannerView.validAdSizes = @[ NSValueFromGADAdSize(GADAdSizeBanner), NSValueFromGADAdSize(GADAdSizeMediumRectangle), NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSizeMake(120, 20))) ];
Implementa il metodo
GADAdSizeDelegate
per rilevare una modifica delle dimensioni dell'annuncio.Swift
public func bannerView(_ bannerView: GADBannerView, willChangeAdSizeTo size: GADAdSize)
Objective-C
- (void)bannerView:(GAMBannerView *)view willChangeAdSizeTo:(GADAdSize)size;
Ricordati di impostare il delegato prima di effettuare la richiesta di un annuncio.
Swift
bannerView.adSizeDelegate = self
Objective-C
self.bannerView.adSizeDelegate = self;