Migrazione dell'SDK

Questa pagina descrive le migrazioni per le versioni attuali e precedenti dell'SDK Google Mobile Ads per iOS. Il rilascio della versione 12.0.0 è previsto per febbraio 2025.

Esegui la migrazione dalla versione 11 alla v12

Esegui l'upgrade a Xcode 16.0

La versione minima supportata di Xcode è stata aumentata a 16.0.

Supporto per la denominazione Swift

La versione 12.0.0 include modifiche per seguire le convenzioni di denominazione nelle linee guida per la progettazione di API di Swift. Queste modifiche riguardano solo Swift. Non sono state apportate modifiche alla denominazione delle API Objective-C.

Modifiche al prefisso della classe

Sono state apportate le seguenti modifiche ai prefissi dei corsi:

  • È stato rimosso il prefisso GAD dai nomi di tutti i tipi.
  • Il prefisso GAM è stato rinominato in AdManager.
  • Il prefisso GADM è stato rinominato in Mediation.

Risolvere gli errori

Il modo migliore per risolvere gli errori derivanti da queste modifiche è apportare una correzione Fix-It.

Risolvere i conflitti di denominazione

Per risolvere i conflitti di denominazione, utilizza lo spazio dei nomi fornito dal modulo. Ad esempio, GADRequest ora si chiama Request. I seguenti spazi dei nomi di esempio la classe Request dell'SDK Google Mobile Ads:

import GoogleMobileAds
...
var request: GoogleMobileAds.Request?

Elenco dettagliato delle modifiche di Swift

Le tabelle seguenti elencano le modifiche apportate alle API Swift:

Versione 11 Versione 12
GADAdapterInitializationState AdapterInitializationState
GADAdChoicesPosition AdChoicesPosition
GADAdChoicesView AdChoicesView
GADAdFormat AdFormat
GADAdLoader AdLoader
GADAdLoaderAdType AdLoaderAdType
GADAdLoaderDelegate AdLoaderDelegate
GADAdMetadataDelegate AdMetadataDelegate
GADAdMetadataProvider AdMetadataProvider
GADAdNetworkExtras AdNetworkExtras
GADAdNetworkResponseInfo AdNetworkResponseInfo
GADAdReward AdReward
GADAdSize AdSize
GADAdSizeDelegate AdSizeDelegate
GADAdValue AdValue
GADAdValuePrecision AdValuePrecision
GADAppEventDelegate AppEventDelegate
GADAppOpenAd AppOpenAd
GADAppOpenSignalRequest AppOpenSignalRequest
GADAudioVideoManager AudioVideoManager
GADAudioVideoManagerDelegate AudioVideoManagerDelegate
GADBannerSignalRequest BannerSignalRequest
GADBannerView BannerView
GADBannerViewDelegate BannerViewDelegate
GADCustomEventExtras CustomEventExtras
GADCustomEventRequest CustomEventRequest
GADCustomNativeAd CustomNativeAd
GADCustomNativeAdLoaderDelegate CustomNativeAdLoaderDelegate
GADCustomNativeAdDelegate CustomNativeAdDelegate
GADDebugOptionsViewControllerDelegate DebugOptionsViewControllerDelegate
GADDebugOptionsViewController DebugOptionsViewController
GADDisplayAdMeasurement DisplayAdMeasurement
GADExtras Extras
GADFullScreenPresentingAd FullScreenPresentingAd
GADFullScreenContentDelegate FullScreenContentDelegate
GADAdapterStatus AdapterStatus
GADInitializationStatus InitializationStatus
GADInterstitialAd InterstitialAd
GADInterstitialSignalRequest InterstitialSignalRequest
GADMediaAspectRatio MediaAspectRatio
GADMediaContent MediaContent
GADMediaView MediaView
GADMobileAds MobileAds
GADMultipleAdsAdLoaderOptions MultipleAdsAdLoaderOptions
GADMuteThisAdReason MuteThisAdReason
GADNativeAd NativeAd
GADNativeAdLoaderDelegate NativeAdLoaderDelegate
GADNativeAdView NativeAdView
GADNativeAdCustomClickGestureOptions NativeAdCustomClickGestureOptions
GADNativeAdDelegate NativeAdDelegate
GADNativeAdImage NativeAdImage
GADNativeAdImageAdLoaderOptions NativeAdImageAdLoaderOptions
GADNativeAdInlineBehavior NativeAdInlineBehavior
GADNativeAdInlineBehaviorOptions NativeAdInlineBehaviorOptions
GADNativeAdMediaAdLoaderOptions NativeAdMediaAdLoaderOptions
GADNativeAdUnconfirmedClickDelegate NativeAdUnconfirmedClickDelegate
GADNativeAdViewAdOptions NativeAdViewAdOptions
GADNativeMuteThisAdLoaderOptions NativeMuteThisAdLoaderOptions
GADNativeSignalRequest NativeSignalRequest
GADPresentationError PresentationError
GADPublisherPrivacyPersonalizationState PublisherPrivacyPersonalizationState
GADQueryInfo QueryInfo
GADRequest Request
GADRequestError RequestError
GADRequestConfiguration RequestConfiguration
GADResponseInfo ResponseInfo
GADRewardedAd RewardedAd
GADRewardedSignalRequest RewardedSignalRequest
GADRewardedInterstitialAd RewardedInterstitialAd
GADRewardedInterstitialSignalRequest RewardedInterstitialSignalRequest
GADSearchBannerView SearchBannerView
GADServerSideVerificationOptions ServerSideVerificationOptions
GADSignal Signal
GADSignalRequest SignalRequest
GADVersionNumber VersionNumber
GADVideoController VideoController
GADVideoControllerDelegate VideoControllerDelegate
Ad Manager
GAMBannerAdLoaderDelegate AdManagerBannerAdLoaderDelegate
GAMBannerView AdManagerBannerView
GAMBannerViewOptions AdManagerBannerViewOptions
GAMInterstitialAd AdManagerInterstitialAd
GAMRequest AdManagerRequest
Mediazione
GADMAdNetworkAdapter MediationAdNetworkAdapter
GADMAdNetworkConnector MediationAdNetworkConnector
GADMBannerAnimationType MediationBannerAnimationType
GADMediatedUnifiedNativeAd MediationUnifiedNativeAd
GADMediatedUnifiedNativeAdNotificationSource MediationUnifiedNativeAdNotificationSource
GADMediationAd MediationAd
GADMediationAdConfiguration MediationAdConfiguration
GADMediationAdEventDelegate MediationAdEventDelegate
GADMediationAdRequest MediationAdRequest
GADMediationAdapter MediationAdapter
GADMediationAppOpenAd MediationAppOpenAd
GADMediationAppOpenAdEventDelegate MediationAppOpenAdEventDelegate
GADMediationBannerAd MediationBannerAd
GADMediationBannerAdConfiguration MediationBannerAdConfiguration
GADMediationBannerAdEventDelegate MediationBannerAdEventDelegate
GADMediationCredentials MediationCredentials
GADMediationInterstitialAd MediationInterstitialAd
GADMediationInterstitialAdConfiguration MediationInterstitialAdConfiguration
GADMediationInterstitialAdEventDelegate MediationInterstitialAdEventDelegate
GADMediationNativeAd MediationNativeAd
GADMediationNativeAdConfiguration MediationNativeAdConfiguration
GADMediationNativeAdEventDelegate MediationNativeAdEventDelegate
GADMediationRewardedAd MediationRewardedAd
GADMediationRewardedAdConfiguration MediationRewardedAdConfiguration
GADMediationRewardedAdEventDelegate MediationRewardedAdEventDelegate
GADMediationServerConfiguration MediationServerConfiguration
Offerta in tempo reale
GADRTBAdapter RTBAdapter
GADRTBMediationSignalsConfiguration RTBMediationSignalsConfiguration
GADRTBRequestParameters RTBRequestParameters

Costanti

Versione 11 Versione 12
GADAdLoaderAdType.gamBanner AdLoaderAdType.adManagerBanner
GADAdSizeBanner AdSizeBanner
GADAdSizeFluid AdSizeFluid
GADAdSizeFullBanner AdSizeFullBanner
GADAdSizeInvalid AdSizeInvalid
GADAdSizeLargeBanner AdSizeLargeBanner
GADAdSizeLeaderboard AdSizeLeaderboard
GADAdSizeMediumRectangle AdSizeMediumRectangle
GADAdSizeSkyscraper AdSizeSkyscraper
GoogleMobileAdsVersionString GoogleMobileAdsVersion

Proprietà

Tipo Versione 11 Versione 12
GADAdLoader loading isLoading
GADAudioVideoManager audioSessionApplicationManaged isAudioSessionApplicationManaged
GADBannerView autoloadEnabled isAutoloadEnabled
GADMobileAds sharedInstance shared
applicationMuted isApplicationMuted
GADMuteThisAdReason reasonDescription reason
GADNativeAd customMuteThisAdAvailable isCustomMuteThisAdAvailable
GADNativeAdCustomClickGestureOptions tapsAllowed areTapsAllowed
GADNativeAdImageAdLoaderOptions imageLoadingDisabled isImageLoadingDisabled
GADNativeMuteThisAdLoaderOptions customMuteThisAdRequested isCustomMuteThisAdRequested
GADNativeSignalRequest imageLoadingDisabled isImageLoadingDisabled
customMuteThisAdRequested isCustomMuteThisAdRequested
GADRequest neighboringContentURLStrings neighboringContentURLs
GADResponseInfo extrasDictionary extras
GADServerSideVerificationOptions customRewardString customRewardText
GADSignal signalString signal
GADSignalRequest neighboringContentURLStrings neighboringContentURLs
GADVideoController customControlsRequested areCustomControlsRequested
clickToExpandEnabled isClickToExpandEnabled
GADVideoOptions startMuted shouldStartMuted
customControlsRequested areCustomControlsRequested
clickToExpandRequested isClickToExpandRequested

Funzioni

Tipo Versione 11 Versione 12
GADAdSize GADPortraitInlineAdaptiveBannerAdSizeWithWidth(_:) portraitInlineAdaptiveBanner(width:)
GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(_:) landscapeInlineAdaptiveBanner(width:)
GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(_:) currentOrientationInlineAdaptiveBanner(width:)
GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(_:, _:) inlineAdaptiveBanner(width:maxHeight:)
GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(_:) portraitAnchoredAdaptiveBanner(width:)
GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(_:) landscapeAnchoredAdaptiveBanner(width:)
GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(_:) currentOrientationAnchoredAdaptiveBanner(width:)
GADAdSizeFromCGSize(_:) adSizeFor(cgSize:)
GADAdSizeFullWidthPortraitWithHeight(_:) fullWidthPortrait(height:)
GADAdSizeFullWidthLandscapeWithHeight(_:) fullWidthLandscape(height:)
GADAdSizeEqualToSize(_:, _:) isAdSizeEqualToSize(size1:size2:)
IsGADAdSizeValid(_:) isAdSizeValid(size:)
GADAdSizeIsFluid(_:) isAdSizeFluid(size:)
CGSizeFromGADAdSize(_:) cgSize(for:)
NSStringFromGADAdSize(_:) string(for:)
NSValueFromGADAdSize(_:) nsValue(for:)
GADAdSizeFromNSValue(_:) adSizeFor(nsValue:)
GADClosestValidSizeForAdSizes(_:_:) closestValidSizeForAdSizes(original:possibleAdSizes:)
GADAppEventDelegate adView(_:didReceiveAppEvent:withInfo:) adView(_:didReceiveAppEvent:with:)
interstitialAd(_:didReceiveAppEvent:withInfo:) adView(_:didReceiveAppEvent:with:)
GADAppOpenAd load(withAdResponseString:) load(with:)
load(withAdUnitID:request:completionHandler:) load(with:request:completionHandler:)
canPresent(fromRootViewController:) canPresent(from:)
present(fromRootViewController:) present(from:)
GADBannerView load(withAdResponseString:) load(with:)
GADInterstitial load(withAdResponseString:) load(with:)
load(withAdUnitID:request:completionHandler:) load(with:request:completionHandler:)
canPresent(fromRootViewController:) canPresent(from:)
present(fromRootViewController:) present(from:)
GADRewardedAd load(withAdResponseString:) load(with:)
load(withAdUnitID:request:completionHandler:) load(with:request:completionHandler:)
canPresent(fromRootViewController:) canPresent(from:)
present(fromRootViewController:userDidEarnRewardHandler:) present(from:userDidEarnRewardHandler:)
GADRewardedInterstitialAd load(withAdResponseString:) load(with:)
load(withAdUnitID:request:completionHandler:) load(with:request:completionHandler:)
canPresent(fromRootViewController:) canPresent(from:)
present(fromRootViewController:userDidEarnRewardHandler:) present(from:userDidEarnRewardHandler:)
GADVersionNumber GADGetStringFromVersionNumber(_ version: GADVersionNumber) string(for:)
Mediazione
GADMAdNetworkAdapter getBannerWith(_:) getBanner(with:)
presentInterstitial(fromRootViewController:) presentInterstitial(from:)
getNativeAd(withAdTypes:options:) getNativeAd(with:options:)
GADMediatedUnifiedNativeAd didRecordClickOnAsset(withName:view:viewController:) didRecordClickOnAsset(with:view:viewController:)
GADMediationAdapter setUpWith(_:completionHandler:) setUp(with:completionHandler:)
GADMediationAdSize present(fromRootViewController:) present(from:)
GADMediationAppOpenAd present(fromRootViewController:) present(from:)
GADMediationInterstitialAd present(fromRootViewController:) present(from:)
GADMediationRewardedAd present(fromRootViewController:) present(from:)
GAMInterstitialAd load(withAdManagerAdUnitID:request:completionHandler:) load(with:request:completionHandler:)

Impostare parametri di targeting personalizzati

Per impostare il targeting personalizzato su una richiesta di annuncio, utilizza customTargeting.

Modifiche all'API per controllare lo stato di disattivazione dell'audio dei video

La proprietà isMuted e il metodo setMute: su GADVideoController sono sostituiti da una proprietà muted.

Modifiche agli annunci adattivi in linea

Per ottimizzare l'utilizzo dello spazio, gli annunci adattivi in linea inizialmente non occupano spazio nel frame. La chiamata di CGSizeFromGADAdSize(_:) con una dimensione dell'annuncio adattivo in linea ora restituisce l'altezza 0 finché l'SDK Google Mobile Ads non restituisce un annuncio.

Rimozione degli annunci associati alla ricerca personalizzati

Le seguenti classi vengono rimosse senza sostituzione:

  • GADDynamicHeightSearchBannerView
  • GADDynamicHeightSearchRequest
  • GADSearchBannerView

Modifiche ai codici di errore

I seguenti codici di errore sono stati modificati:

Classe Note
GADErrorMediationNoFill Ora gli errori vengono restituiti come GADErrorNoFill.
GADErrorReceivedInvalidResponse È stato sostituito da GADErrorReceivedInvalidAdString.

Rimozione di GADSimulatorID

GADSimulatorID rimosso. Per impostazione predefinita, i simulatori sono già in modalità di test.

Modifiche al targeting personalizzato

Il dizionario customTargeting su GADRequest ora utilizza Any anziché String come tipo di valore. In questo modo puoi trasmettere valori numerici all'API.

Modifiche ai parametri degli extra

Eseguire la migrazione dalla versione 10 alla versione 11

Destinazione di deployment minima

La destinazione di deployment minima è stata aumentata a iOS 12.

Versione minima di Xcode

La versione minima supportata di Xcode è stata aumentata a 15.1.

Interruzione della pubblicazione degli annunci su iOS 12

L'SDK Google Mobile Ads versione 11.0.0 pubblica annunci solo su dispositivi con iOS 13 e versioni successive.

Rimossa la dipendenza GoogleAppMeasurement

Nella versione 11.0.0, la dipendenza da GoogleAppMeasurement è stata rimossa. Questa dipendenza che alimentava il pulsante di attivazione/disattivazione delle metriche utente in AdMob verrà ritirata all'inizio del 2024. Per continuare a raccogliere metriche utente in AdMob, collega l'app AdMob a Firebase e integra l'SDK Google Analytics for Firebase nella tua app.

Modifiche alla presentazione degli annunci a schermo intero

Le seguenti modifiche interessano i vari formati degli annunci:

  • Apertura app
  • Interstitial
  • Con premio
  • Interstitial con premio

Il parametro del controller di visualizzazione in -canPresentFromRootViewController:error: e -presentFromRootViewController: è annullabile. Se viene passato nil, l'annuncio viene presentato dal controller di visualizzazione più in alto nella gerarchia dei controller di visualizzazione.

Metodi rimossi

I seguenti metodi vengono rimossi.

v11.0.0 Tipo Metodo Note
GADAppOpenAd load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) Utilizza load(withAdUnitID adUnitID: String, request: GADRequest?).
GADMediationBannerAdEventDelegate willBackgroundApplication() Nessuna sostituzione.
GADMediationInterstitialAdEventDelegate willBackgroundApplication() Nessuna sostituzione.
GADMediationNativeAdEventDelegate willBackgroundApplication() Nessuna sostituzione.
GADMediationRewardedAdEventDelegate didRewardUser(with reward: GADAdReward) Utilizza didRewardUser().
GADMediatedUnifiedNativeAdNotificationSource mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) Nessuna sostituzione.
GADRequestConfiguration setSameAppKeyEnabled(_ enabled: Bool) Utilizza invece setPublisherFirstPartyIDEnabled(_ enabled: Bool).
tagForUnderAge(ofConsent underAgeOfConsent: Bool) Utilizza invece la proprietà tagForUnderAgeOfConsent.
tag(forChildDirectedTreatment childDirectedTreatment: Bool) Utilizza invece la proprietà tagForChildDirectedTreatment.

Proprietà rimosse

Le seguenti proprietà vengono rimosse.

v11.0.0 Class Proprietà Note
GADMediationAdConfiguration hasUserLocation Nessuna sostituzione.
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment Utilizza GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment.
GADResponseInfo adNetworkClassName Utilizza invece adNetworkClassName di loadedAdNetworkResponseInfo.

Rimozione di GADAdFormatUnknown

GADAdFormatUnknown è stato rimosso senza sostituzione.

Modifiche alla registrazione della versione dell'SDK

La versione 11.0.0 rimuove sdkVersion. Per registrare la versione dell'SDK Google Mobile Ads, utilizza versionNumber.

Versione 10.0.0

GADMobileAds.sharedInstance().sdkVersion

Versione 11.0.0

GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)

Modifiche alla gestione degli errori di GADAdLoader

A partire dalla versione 11.0.0, GADAdLoader non effettua una richiesta di annuncio se il suo delegate non è conforme al protocollo delegato dei tipi di annunci richiesti. In precedenza, l'errore si verificava dopo l'invio della richiesta di annuncio.

Modifiche al comportamento dei test

Consulta la tabella che mostra le condizioni aggiornate in base alle quali le seguenti proprietà restituiscono true.

Classe Proprietà
GADMediationAdConfiguration isTestRequest
GADCustomEventRequest isTesting
v10.0.0 v11.0.0
  • Il dispositivo è dichiarato esplicitamente come dispositivo di test in testDeviceIdentifiers.
  • Il dispositivo è dichiarato esplicitamente come dispositivo di test in testDeviceIdentifiers.
  • Il dispositivo è un simulatore.
  • Il dispositivo è dichiarato esplicitamente come dispositivo di test nell'interfaccia utente di Ad Manager.

Eseguire la migrazione dalla versione 9 alla versione 10

Gli annunci non vengono più pubblicati su iOS 11

L'SDK Google Mobile Ads versione 10.0.0 pubblica annunci solo su dispositivi con iOS 12 e versioni successive.

L'upgrade all'SDK Google Mobile Ads versione 10.0.0 non danneggerà la tua app sui dispositivi iOS 11 e iOS 10, ma su questi dispositivi non verranno pubblicati annunci.

Requisito dell'ID app Ad Manager

L'ID app Ad Manager è ora obbligatorio in Info.plist per tutte le app Ad Manager e richiede il formato ca-app-pub-################~##########. Per maggiori dettagli, consulta Aggiornare il file Info.plist.

Requisito di GoogleAppMeasurement.xcframework

GoogleAppMeasurement.xcframework è ora obbligatorio per tutte le app Ad Manager. Se installi l'SDK Google Mobile Ads tramite Cocoapods o Swift Package Manager, non è richiesta alcuna azione aggiuntiva. Se installi i framework manualmente, consulta la sezione Download manuale per maggiori dettagli.

La creazione con bitcode non è più supportata

La disattivazione di bitcode nelle tue app mobile è ora obbligatoria per integrare l'SDK Google Mobile Ads.

Tipi rimossi

Tipo Note
GADGender Nessuna sostituzione.
GADMRewardBasedVideoAdNetworkAdapterProtocol Tutti gli adattatori di mediazione con premi elencati in Scegli reti hanno smesso di utilizzare questi protocolli da oltre un anno. Utilizza GADMediationAdapter per la mediazione e gli eventi personalizzati.
GADMRewardBasedVideoAdNetworkConnectorProtocol

Proprietà rimosse

Le seguenti proprietà vengono rimosse senza sostituzione.

v10.0.0 Class Proprietà
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

Esegui la migrazione dalla versione 8 alla versione 9

Interruzione della pubblicazione degli annunci su iOS 10

La versione minima di iOS supportata dalla versione 9.0.0 dell'SDK Google Mobile Ads è iOS 11.

L'upgrade all'SDK Google Mobile Ads versione 9.0.0 non interromperà il funzionamento dell'app sui dispositivi iOS 10, ma non verranno pubblicati annunci su questi dispositivi.

Applicazione più rigorosa dei controlli della barra di stato

A partire dalla versione 9.0.0, quando presenti annunci in formato a schermo intero, la tua app deve garantire che gli annunci siano in grado di controllare la presentazione della barra di stato. Se non lo fai, nei log verrà visualizzato un messaggio di errore.

A seconda del layout specifico dei controller di visualizzazione nella tua app, potresti non dover apportare modifiche per assicurarti che ciò avvenga. Valuta se devi impostare la proprietà childViewControllerForStatusBarHidden nel rootViewController del tuo annuncio.

Rinomina adDidPresentFullScreenContent: in adWillPresentFullScreenContent:

Non sono previsti cambiamenti nel comportamento. Il metodo del delegato viene richiamato subito prima che l'annuncio venga presentato, quindi il nuovo nome del metodo riflette meglio la sua funzionalità.

Rimuovi l'API di impostazione della posizione in GADRequest

- (void)setLocationWithLatitude:longitude:accuracy: è stato eliminato da GADRequest poiché i dati sulla posizione non vengono utilizzati da Google per scegliere gli annunci target. Utilizza API di terze parti per fornire le informazioni alle reti pubblicitarie di terze parti, se necessario.

Ritiro delle interfacce degli eventi personalizzati

Gli eventi personalizzati consentono ai publisher che utilizzano la mediazione Ad Manager di aggiungere la mediazione a cascata per una rete pubblicitaria che non è una delle reti pubblicitarie supportate.

Tutti i protocolli di eventi personalizzati sono ritirati. Utilizza invece i protocolli GADMediationAdapter e GADMediationAdEventDelegate esistenti per ottenere le stesse funzionalità. Questa modifica migliora la chiarezza e ti consente di creare eventi personalizzati per gli annunci con premio e interscroller che non erano disponibili in precedenza.

API

La tabella seguente elenca le API degli adattatori di mediazione corrispondenti alle API degli eventi personalizzati che devono essere utilizzate a partire dalla versione 9.0.0.

v8 v9
GADCustomEventBanner
GADCustomEventInterstitial
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediationInterstitialAd
GADMediationInterscrollerAd
GADMediationRewardedAd
GADMediationNativeAd
delegate Delegate viene restituito dal gestore di completamento del caricamento di ogni funzione di caricamento della classe GADMediationAdapter
-init -init
-requestBannerAd:parameter:label:request: -loadBannerForAdConfiguration:completionHandler:
-requestInterstitialAdWithParameter:label:request: -loadInterstitialForAdConfiguration:completionHandler:
-requestNativeAdWithParameter:request:adTypes:options:rootViewController: -loadNativeAdForAdConfiguration:completionHandler:
N/D -loadInterscrollerAdForAdConfiguration:completionHandler:
N/D -loadRewardedAdForAdConfiguration:completionHandler:
-presentFromRootViewController: -presentFromViewController:
-handlesUserClicks -handlesUserClicks
-handlesUserImpressions -handlesUserImpressions

Metodi di delega

La tabella seguente elenca i metodi delegati degli eventi annuncio di mediazione corrispondenti ai metodi delegati degli eventi personalizzati che devono essere utilizzati a partire dalla versione 9.0.0.

v8 v9
GADCustomEventBannerDelegate
GADCustomEventInterstitialDelegate
GADCustomEventNativeAdDelegate
GADMediationAdEventDelegate GADMediationAd
-customEventBanner:didReceiveAd:
-customEventInterstitialDidReceiveAd:
Lo stato di caricamento degli annunci è incluso nel gestore di completamento del caricamento di ogni funzione di caricamento nella classe GADMediationAdapter
-customEventBanner:didFailAd:
-customEventInterstitial:didFailAd:
-customEventBannerWasClicked:
-customEventInterstitialWasClicked:
-reportClick
-customEventBannerWillPresentModal:
-customEventInterstitialWillPresentModal:
-willPresentFullScreenView
-customEventBannerWillDismissModal:
-customEventInterstitialWillDismissModal:
-willDismissFullScreenView
-customEventBannerDidDismissModal:
-customEventInterstitialDidDismissModal:
-didDismissFullScreenView
-customEventBannerWillLeaveApplication:
-customEventInterstitialWillLeaveApplication:
-willBackgroundApplication
viewControllerForPresentingModalView -[GADMediationBannerAd view]

Altri metodi e costanti rimossi/sostituiti

Modifiche a metodo, costante o proprietà
Costanti con prefisso kGAD- Rimosso. Utilizza costanti con il prefisso GAD-.
GADAdNetworkResponseInfo credentials sono stati rimossi. Usa invece adUnitMapping.
GAMRequest kGAMSimulatorID in GAMRequest è deprecato. Utilizza GADSimulatorID in GADRequestConfiguration invece.
GADCustomNativeAd mediaView in GADCustomNativeAd è deprecato. Utilizza invece mediaContent.
API In-app Purchase in GoogleMobileAds Le API inAppPurchase in GoogleMobileAds sono state rimosse.

Eseguire la migrazione dalla versione 7 alla versione 8

La versione 8.0.0 dell'SDK Google Mobile Ads presenta alcuni cambiamenti importanti oltre a modifiche di nomi e rimozioni di alcune API.

Aggiornamenti dell'API per il formato a schermo intero

A partire dalla versione 8.0.0, gli annunci interstitial e con premio condividono uno stile generico di annuncio a schermo intero per una maggiore coerenza. Queste nuove API per gli annunci a schermo intero presentano due differenze principali rispetto alle API per gli annunci a schermo intero della versione 7:

  1. Metodo statico della classe load.

    L'approccio precedente per caricare/mostrare un annuncio a schermo intero è il seguente:

    1. Crea un'istanza dell'oggetto annuncio e mantieni un riferimento.
    2. Assegna un delegato che gestisca i callback di caricamento e visualizzazione.
    3. Carica un annuncio.
    4. Controlla se l'annuncio è caricato utilizzando isReady.
    5. Mostra l'annuncio.

    Nella versione 8, l'approccio cambia leggermente. I callback di caricamento non fanno più parte di un delegato. ma vengono passati al metodo load come gestore del completamento:

    1. Chiama un metodo di caricamento statico nella classe dell'annuncio e fornisci un gestore di completamento del caricamento.
    2. Nel callback di completamento del caricamento, mantieni un riferimento all'annuncio caricato restituito.
    3. Assegna un delegato che gestisca i callback dello show.
    4. Mostra l'annuncio.

    Il nuovo approccio offre i seguenti vantaggi:

    • Non avrai mai un riferimento a un annuncio non caricato.
    • Non devi tenere premuto un oggetto annuncio durante il caricamento.
  2. Eventi annuncio coerenti.

    Tipo di evento API esistente API v8
    Eventi di caricamento GADInterstitialDelegate o GADRewardedAdDelegate GAMInterstitialAdLoadCompletionHandler o GADRewardedAdLoadCompletionHandler
    Eventi di presentazione GADFullScreenContentDelegate

    In precedenza, per ascoltare gli eventi annuncio, registravi una classe che implementava il protocollo GADInterstitialDelegate nella proprietà delegata di un annuncio interstitial oppure registravi una classe che implementava il protocollo GADRewardedAdDelegate nella proprietà delegata di un annuncio con premio, a seconda del formato che utilizzi. Lo stesso delegato aveva metodi correlati sia al ciclo di vita di caricamento sia a quello di presentazione di un annuncio.

    Nella versione 8, gli eventi di caricamento e presentazione sono separati. Ora puoi registrare un GADFullScreenContentDelegate in qualsiasi momento prima della pubblicazione di un annuncio, anziché dover impostare un singolo delegato prima del caricamento dell'annuncio. Gli eventi di caricamento degli annunci, specifici per ogni formato, vengono spostati in un unico gestore di completamento del caricamento passato nel metodo di caricamento.

Interstitial

Carica annuncio

I seguenti snippet di codice mostrano come caricare un annuncio interstitial e ascoltare gli eventi quando l'annuncio viene caricato correttamente o non viene caricato.

Versione 7

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADInterstitialDelegate {

  var interstitial: DFPInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()
    interstitial = DFPInterstitial(adUnitID: "/21775744923/example/interstitial")
    interstitial.delegate = self
    let request = GAMRequest()
    interstitial.load(request)
  }

  /// Tells the delegate an ad request succeeded.
  func interstitialDidReceiveAd(_ ad: DFPInterstitial) {
    print("Interstitial ad loaded.")
  }

  /// Tells the delegate an ad request failed.
  func interstitial(_ ad: DFPInterstitial, didFailToReceiveAdWithError error: GADRequestError) {
    print("Interstitial ad failed to load with error: \(error.localizedDescription)")
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) DFPInterstitial *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.interstitial = [[DFPInterstitial alloc]
      initWithAdUnitID:@"/21775744923/example/interstitial"];
  self.interstitial.delegate = self;
  GAMRequest *request = [GAMRequest request];
  [self.interstitial loadRequest:request];
}

/// Tells the delegate an ad request succeeded.
- (void)interstitialDidReceiveAd:(DFPInterstitial *)ad {
  NSLog(@"Insterstitial ad loaded.");
}

/// Tells the delegate an ad request failed.
- (void)interstitial:(DFPInterstitial *)ad
    didFailToReceiveAdWithError:(GADRequestError *)error {
  NSLog(@"Interstitial ad failed to load with error: %@", [error localizedDescription]);
}

v8

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADFullScreenContentDelegate {

  var interstitial: GAMInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    let request = GAMRequest()
    GAMInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738",
                                request: request,
                      completionHandler: { (ad, error) in
                        if let error = error {
                          print("Failed to load interstitial ad with error: \(error.localizedDescription)")
                          return
                        }
                        self.interstitial = ad
                        self.interstitial.fullScreenContentDelegate = self
                      }
    )
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GAMInterstitialAd *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  GAMRequest *request = [GAMRequest request];
  [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial"
                              request:request
                    completionHandler:^(GAMInterstitialAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
      return;
    }
    self.interstitial = ad;
    self.interstitial.fullScreenContentDelegate = self;
  }];
}

Annuncio display

Versione 7

Swift

func showInterstitial() {
  ...
  if interstitial.isReady {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}

Objective-C

- (void)showInterstitial: {
  ...
  if (self.interstitial.isReady) {
    [self.interstitial presentFromRootViewController:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

v8

Swift

func showInterstitial() {
  ...
  if let ad = interstitial {
    ad.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}

Objective-C

- (void)showInterstitial: {
  ...
  if (self.interstitial) {
    [self.interstitial presentFromRootViewController:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

Eventi annuncio presentazione

I seguenti snippet di codice mostrano come gestire i callback quando l'annuncio viene visualizzato (correttamente o meno) e quando viene chiuso.

Versione 7

Swift

override func viewDidLoad() {
  super.viewDidLoad()
  interstitial = DFPInterstitial(adUnitID: "/21775744923/example/interstitial")
  interstitial.delegate = self
  ...
}

/// Tells the delegate that an interstitial will be presented.
func interstitialWillPresentScreen(_ ad: DFPInterstitial) {
  print("Interstitial ad will be presented.")
}

/// Tells the delegate the interstitial is to be animated off the screen.
func interstitialWillDismissScreen(_ ad: DFPInterstitial) {
  print("Interstitial ad will be dismissed.")
}

/// Tells the delegate the interstitial had been animated off the screen.
func interstitialDidDismissScreen(_ ad: DFPInterstitial) {
  print("Interstitial ad dismissed.")
}

/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
///
/// This is not a reliable callback for an ad click event and is removed in
/// version 8. If you wish to listen to an ad causing a user to leave the app,
/// use applicationWillResignActive: or sceneWillResignActive: instead.
func interstitialWillLeaveApplication(_ ad: DFPInterstitial) {
  print("Interstitial ad will leave application.")
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];
  self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:"/21775744923/example/interstitial"];
  self.interstitial.delegate = self;
  ...
}

/// Tells the delegate that an interstitial will be presented.
- (void)interstitialWillPresentScreen:(DFPInterstitial *)ad {
  NSLog(@"Interstitial ad will be presented.");
}

/// Tells the delegate the interstitial is to be animated off the screen.
- (void)interstitialWillDismissScreen:(DFPInterstitial *)ad {
  NSLog(@"Interstitial ad will be dismissed.");
}

/// Tells the delegate the interstitial had been animated off the screen.
- (void)interstitialDidDismissScreen:(DFPInterstitial *)ad {
  NSLog(@"Interstitial ad dismissed.");
}

/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
///
/// This is not a reliable callback for an ad click event and is removed in
/// version 8. If you wish to listen to an ad causing a user to leave the app,
/// use applicationWillResignActive: or sceneWillResignActive: instead.
- (void)interstitialWillLeaveApplication:(DFPInterstitial *)ad {
  NSLog(@"Interstitial ad will leave application.");
}

v8

Swift

override func viewDidLoad() {
  super.viewDidLoad()
  let request = GAMRequest()
  GAMInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738",
                              request: request,
                    completionHandler: { (ad, error) in
                      if let error = error {
                        print(error.localizedDescription)
                        return
                      }
                      self.interstitial = ad
                      self.interstitial.fullScreenContentDelegate = self
                    }
  )
}

func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Ad did present full screen content.")
}

func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
  print("Ad failed to present full screen content with error \(error.localizedDescription).")
}

func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Ad did dismiss full screen content.")
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];
  GAMRequest *request = [GAMRequest request];
  [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial"
                              request:request
                    completionHandler:^(GAMInterstitialAd *ad, NSError *error) {
    if (error) {
      NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription])
      return;
    }
    self.interstitial = ad;
    self.interstitial.fullScreenContentDelegate = self;
  }];
}

- (void)adDidPresentFullScreenContent:(id)ad {
  NSLog(@"Ad did present full screen content.");
}

- (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
  NSLog(@"Ad failed to present full screen content with error %@.", [error localizedDescription]);
}

- (void)adDidDismissFullScreenContent:(id)ad {
  NSLog(@"Ad did dismiss full screen content.");
}

Con premio

Carica annuncio

Versione 7

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADRewardedAdDelegate {
  /// The rewarded ad.
  var rewardedAd: GADRewardedAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313")
    rewardedAd.delegate = self
    rewardedAd?.load(GAMRequest()) { error in
      if let error = error {
        print("Rewarded ad failed to load with error: \(error.localizedDescription)")
      } else {
        print("Rewarded ad loaded.")
      }
    }
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.rewardedAd = [[GADRewardedAd alloc]
      initWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"];
  self.rewardedAd.delegate = self;
  GAMRequest *request = [GAMRequest request];
  [self.rewardedAd loadRequest:request completionHandler:^(GADRequestError * _Nullable error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
    } else {
      NSLog(@"Rewarded ad loaded.");
    }
  }];
}

v8

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADFullScreenContentDelegate {
  /// The rewarded ad.
  var rewardedAd: GADRewardedAd?

  override func viewDidLoad() {
  super.viewDidLoad()
  let request = GAMRequest()
  GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136",
                          request: request, completionHandler: { (ad, error) in
                            if let error = error {
                              print("Rewarded ad failed to load with error: \(error.localizedDescription)")
                              return
                            }
                            self.rewardedAd = ad
                            self.rewardedAd?.fullScreenContentDelegate = self
                          }
  )
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  GAMRequest *request = [GAMRequest request];
  [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"
                          request:request
                completionHandler:^(GADRewardedAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
      return;
    }
    self.rewardedAd = ad;
    NSLog(@"Rewarded ad loaded.");
    self.rewardedAd.fullScreenContentDelegate = self;
}

Visualizzare l'annuncio e gestire la ricompensa

Gli annunci con premio richiedono di gestire l'evento quando un utente guadagna un premio. Con la versione 7 dell'API GADRewardedAd, implementi rewardedAd:userDidEarnReward: come parte del protocollo GADRewardedAdDelegate. Per la versione 8, implementa GADUserDidEarnRewardHandler per mostrare l'annuncio.

Versione 7

Swift

func showRewardedAd() {
  ...
  if rewardedAd.isReady {
    rewardedAd.present(fromRootViewController: self delegate:self)
  } else {
    print("Ad wasn't ready")
  }
}

/// Tells the delegate that the user earned a reward.
func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarnReward: GADAdReward) {
  // TODO: Reward the user.
}

Objective-C

- (void)showRewardedAd: {
  ...
  if (self.rewardedAd.isReady) {
    [self.rewardedAd presentFromRootViewController:self delegate:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

/// Tells the delegate that the user earned a reward.
- (void)rewardedAd:(GADRewardedAd *)rewardedAd userDidEarnReward:(GADAdReward *)reward {
  // TODO: Reward the user.
}

v8

Swift

func showRewardedAd() {
  ...
  if let ad = rewardedAd {
      ad.present(fromRootViewController: self,
               userDidEarnRewardHandler: {
                 let reward = ad.adReward
                 // TODO: Reward the user.
               }
      )
  } else {
    print("Ad wasn't ready")
  }
}

Objective-C

- (void)showRewardedAd: {
  ...
  if (self.rewardedAd) {
    [self.rewardedAd presentFromRootViewController:self
                          userDidEarnRewardHandler:^ {
      GADAdReward *reward = self.rewardedAd.adReward;
      // TODO: Reward the user.
    }];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

Eventi annuncio presentazione

Con l'API GADRewardedAd, passi un GADRewardedAdDelegate al metodo che presenta l'annuncio. Con l'API GADRewardedAd, imposti un GADFullscreenContentDelegate come proprietà dell'annuncio prima di presentarlo.

Versione 7

Swift

func showRewardedAd() {
  ...
  if rewardedAd.isReady {
    rewardedAd.present(fromRootViewController: self delegate:self)
  } else {
    print("Ad wasn't ready")
  }
}

/// Tells the delegate that the rewarded ad was presented.
func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) {
  print("Rewarded ad presented.")
}
/// Tells the delegate that the rewarded ad was dismissed.
func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) {
  print("Rewarded ad dismissed.")
}
/// Tells the delegate that the rewarded ad failed to present.
func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) {
  print("Rewarded ad failed to present with error: \(error.localizedDescription).")
}

Objective-C

- (void)showRewardedAd: {
  ...
  if (self.rewardedAd.isReady) {
    [self.rewardedAd presentFromRootViewController:self delegate:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

/// Tells the delegate that the rewarded ad was presented.
- (void)rewardedAdDidPresent:(GADRewardedAd *)rewardedAd {
  NSLog(@"Rewarded ad presented.");
}

/// Tells the delegate that the rewarded ad failed to present.
- (void)rewardedAd:(GADRewardedAd *)rewardedAd didFailToPresentWithError:(NSError *)error {
  NSLog(@"Rewarded ad failed to present with error: %@",
        [error localizedDescription]);
}

/// Tells the delegate that the rewarded ad was dismissed.
- (void)rewardedAdDidDismiss:(GADRewardedAd *)rewardedAd {
  NSLog(@"Rewarded ad dismissed.");
}

v8

Swift

override func viewDidLoad() {
  super.viewDidLoad()
  let request = GAMRequest()
  GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136",
                          request: request, completionHandler: { (ad, error) in
                            if let error = error {
                              print(error.localizedDescription)
                              return
                            }
                            self.rewardedAd = ad
                            self.rewardedAd?.fullScreenContentDelegate = self
                          }
  )
}

/// Tells the delegate that the rewarded ad was presented.
func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Rewarded ad presented.")
}
/// Tells the delegate that the rewarded ad was dismissed.
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Rewarded ad dismissed.")
}
/// Tells the delegate that the rewarded ad failed to present.
func ad(_ ad: GADFullScreenPresentingAd,
    didFailToPresentFullScreenContentWithError error: Error) {
  print("Rewarded ad failed to present with error: \(error.localizedDescription).")
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  GAMRequest *request = [GAMRequest request];
  [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"
                          request:request
                completionHandler:^(GADRewardedAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
      return;
    }
    self.rewardedAd = ad;
    NSLog(@"Rewarded ad loaded.");
    self.rewardedAd.fullScreenContentDelegate = self;
}

/// Tells the delegate that the rewarded ad was presented.
- (void)adDidPresentFullScreenContent:(id)ad {
  NSLog(@"Rewarded ad presented.");
}

/// Tells the delegate that the rewarded ad failed to present.
- (void)ad:(id)ad
    didFailToPresentFullScreenContentWithError:(NSError *)error {
  NSLog(@"Rewarded ad failed to present with error: %@",
       [error localizedDescription]);
}

/// Tells the delegate that the rewarded ad was dismissed.
- (void)adDidDismissFullScreenContent:(id)ad {
  NSLog(@"Rewarded ad dismissed.");
}

Rimozione dell'API GADRewardedBasedVideoAd legacy

La nuova GADRewardedAd API è stata introdotta per la prima volta a marzo 2019 ed è stata l'API premiata preferita per oltre 18 mesi. Ha subito più miglioramenti rispetto all'API GADRewardedBasedVideoAd legacy, tra cui la possibilità di caricare più di un annuncio con premio alla volta.

L'API legacy GADRewardedBasedVideoAd viene rimossa nella versione 8.0.0 dell'SDK.

Ritiro del banner intelligente a favore del banner adattivo

Gli annunci banner intelligenti non sono più supportati a favore degli annunci banner adattivi. I banner adattivi offrono un rendimento superiore e una maggiore flessibilità nella definizione della larghezza dell'annuncio. Se preferisci continuare a utilizzare i banner a larghezza intera, puoi comunque farlo utilizzando il banner adattivo, come mostrato nel seguente snippet di codice:

Swift

class ViewController: UIViewController {

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    // Note: The safe area is not known until viewWillAppear.
    let adSize = getFullWidthAdaptiveAdSize()
  }

  func getFullWidthAdaptiveAdSize() -> GADAdSize {
    // Here safe area is taken into account, hence the view frame is used after the
    // view has been laid out.
    let frame = { () -> CGRect in
      if #available(iOS 11.0, *) {
        return view.frame.inset(by: view.safeAreaInsets)
      } else {
        return view.frame
      }
    }()
    return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width)
  }
}

Objective-C

@implementation ViewController

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  // Note: The safe area is not known until viewWillAppear.
  GADAdSize adSize = [self getFullWidthAdaptiveAdSize];
}

- (GADAdSize)getFullWidthAdaptiveAdSize {
  CGRect frame = self.view.frame;
  // Here safe area is taken into account, hence the view frame is used after
  // the view has been laid out.
  if (@available(iOS 11.0, *)) {
    frame = UIEdgeInsetsInsetRect(self.view.frame, self.view.safeAreaInsets);
  }
  return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width);
}

@end

Abbandona la rimozione del callback dell'applicazione

Il willLeaveApplication callback per tutti i formati degli annunci è stato rimosso a favore dei metodi applicationDidEnterBackground: e sceneDidEnterBackground:. Utilizzando le API a livello di sistema operativo, ti viene inviata una notifica ogni volta che gli utenti escono dalla tua app, indipendentemente dal fatto che ciò sia dovuto o meno a un'interazione con un annuncio.

Tieni presente che il callback willLeaveApplication non è mai stato pensato per essere un gestore di clic sugli annunci e fare affidamento su questo callback per segnalare i clic non produce una metrica accurata. Ad esempio, un clic sull'icona AdChoices che ha avviato un browser esterno ha richiamato il callback, ma non ha conteggiato un clic.

Ridenominazioni delle classi

La tabella seguente elenca i nomi delle classi specifici che sono stati modificati o rimossi nella versione 8. In sintesi:

  • Tutti i corsi correlati a GADUnifiedNativeAd sono stati rinominati in GADNativeAd.
  • GADRewardBasedVideoAd, GADNativeExpressAdView e GADInstreamAd sono stati rimossi.
  • Tutte le classi con il prefisso DFP sono state sostituite con un prefisso GAM.
Classe v7.68.0 v8.0.0 Class
DFPBannerView GAMBannerView
DFPBannerViewOptions GAMBannerViewOptions
DFPInterstitial GAMInterstitialAd
DFPRequest GAMRequest
GADRequestError NSError
GADUnifiedNativeAdView GADNativeAdView
GADUnifiedNativeAd GADNativeAd
GADUnifiedNativeAdAssetIdentifiers GADNativeAdAssetIdentifiers
GADUnifiedNativeAdDelegate GADNativeAdDelegate
GADUnifiedNativeAdUnconfirmedClickDelegate GADNativeAdUnconfirmedClickDelegate
GADNativeCustomTemplateAd GADCustomNativeAd
GADNativeCustomTemplateAdLoaderDelegate GADCustomNativeAdLoaderDelegate
GADNativeAdDelegate GADCustomNativeAdDelegate
GADInAppPurchase Rimosso
GADInterstitial GADInterstitialAd
GADNativeExpressAdView Rimosso
GADRewardBasedVideoAd Rimosso
GADInstreamAd Rimosso
GADInstreamAdView Rimosso

Metodi rimossi/sostituiti

La tabella seguente elenca le modifiche specifiche della versione 8. In sintesi:

  • I metodi e le proprietà deprecati in precedenza sono stati rimossi.
  • I metodi di delega -willLeaveApplication: sono stati rimossi per tutti i formati.
  • Il nome della classe della rete pubblicitaria è stato spostato nella proprietà GADResponseInfo.
  • L'identificatore del dispositivo di test è stato spostato nella proprietà GADRequestConfiguration.
Classe v7.68.0 API v7.68.0 API v8.0.0 Note
GADMobileAds +configureWithApplicationID: -startWithCompletionHandler: L'ID app è ora impostato in Info.plist.
+disableAutomatedInAppPurchaseReporting -disableAutomatedInAppPurchaseReporting
+disableSDKCrashReporting -disableSDKCrashReporting
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers La proprietà testDeviceIdentifiers si applica a tutte le richieste di annunci, mentre la vecchia proprietà testDevices veniva impostata per richiesta.
genere Rimosso
compleanno Rimosso
+sdkVersion GADMobileAds.sharedInstance.sdkVersion
-setBirthdayWithMonth:day:year: Rimosso
-setLocationWithDescription: -setLocationWithLatitude:longitude:accuracy:
-tagForChildDirectedTreatment: [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment]
GADErrorCode kGADError* GADError* Il prefisso k viene eliminato da tutte le costanti del codice di errore.
GADBannerView hasAutoRefreshed autoloadEnabled
inAppPurchaseDelegate Rimosso
mediatedAdView Rimosso
adNetworkClassName responseInfo.adNetworkClassName
DFPBannerView -setValidAdSizesWithSizes: -setValidAdSizes:
DFPBannerViewOptions -adSizeDelegate Rimosso
GADBannerViewDelegate -adViewDidReceiveAd: -bannerViewDidReceiveAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewWillPresentScreen: -bannerViewWillPresentScreen:
-adViewWillDismissScreen: -bannerViewWillDismissScreen:
-adViewDidDismissScreen: -bannerViewDidDismissScreen:
-adViewWillLeaveApplication: Rimosso
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediaAspectRatio
GADInterstitial inAppPurchaseDelegate Rimosso
isReady Rimosso Utilizza invece canPresentFromRootViewController:error:.
hasBeenUsed Rimosso
-init -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName responseInfo.adNetworkClassName
-interstitialWillLeaveApplication: Rimosso
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName responseInfo.adNetworkClassName